34 #include <QDomDocument> 36 #include <QDomElement> 44 return QString(
"%1,%2,%3,%4" ).arg( color.red() ).arg( color.green() ).arg( color.blue() ).arg( color.alpha() );
49 QStringList lst = str.split(
"," );
50 if ( lst.count() < 3 )
54 int red, green, blue, alpha;
56 green = lst[1].toInt();
57 blue = lst[2].toInt();
59 if ( lst.count() > 3 )
61 alpha = lst[3].toInt();
63 return QColor( red, green, blue, alpha );
68 return QString::number( alpha / 255.0,
'f', 2 );
74 double alpha = str.toDouble( &ok );
75 if ( !ok || alpha > 1 )
86 case QFont::StyleNormal:
return "normal";
87 case QFont::StyleItalic:
return "italic";
88 case QFont::StyleOblique:
return "oblique";
95 if ( str ==
"normal" )
return QFont::StyleNormal;
96 if ( str ==
"italic" )
return QFont::StyleItalic;
97 if ( str ==
"oblique" )
return QFont::StyleOblique;
98 return QFont::StyleNormal;
103 if ( weight == 50 )
return "normal";
104 if ( weight == 75 )
return "bold";
108 if ( weight < 0 )
return "100";
109 if ( weight > 99 )
return "900";
110 return QString::number( weight * 800 / 99 + 100 );
116 int weight = str.toInt( &ok );
117 if ( !ok )
return (
int ) QFont::Normal;
121 if ( weight > 900 )
return 99;
122 if ( weight < 100 )
return 0;
123 return ( weight - 100 ) * 99 / 800;
130 case Qt::NoPen:
return "no";
131 case Qt::SolidLine:
return "solid";
132 case Qt::DashLine:
return "dash";
133 case Qt::DotLine:
return "dot";
134 case Qt::DashDotLine:
return "dash dot";
135 case Qt::DashDotDotLine:
return "dash dot dot";
136 default:
return "???";
142 if ( str ==
"no" )
return Qt::NoPen;
143 if ( str ==
"solid" )
return Qt::SolidLine;
144 if ( str ==
"dash" )
return Qt::DashLine;
145 if ( str ==
"dot" )
return Qt::DotLine;
146 if ( str ==
"dash dot" )
return Qt::DashDotLine;
147 if ( str ==
"dash dot dot" )
return Qt::DashDotDotLine;
148 return Qt::SolidLine;
155 case Qt::BevelJoin:
return "bevel";
156 case Qt::MiterJoin:
return "miter";
157 case Qt::RoundJoin:
return "round";
158 default:
return "???";
164 if ( str ==
"bevel" )
return Qt::BevelJoin;
165 if ( str ==
"miter" )
return Qt::MiterJoin;
166 if ( str ==
"round" )
return Qt::RoundJoin;
167 return Qt::BevelJoin;
174 case Qt::BevelJoin:
return "bevel";
175 case Qt::MiterJoin:
return "mitre";
176 case Qt::RoundJoin:
return "round";
183 if ( str ==
"bevel" )
return Qt::BevelJoin;
184 if ( str ==
"mitre" )
return Qt::MiterJoin;
185 if ( str ==
"round" )
return Qt::RoundJoin;
186 return Qt::BevelJoin;
193 case Qt::SquareCap:
return "square";
194 case Qt::FlatCap:
return "flat";
195 case Qt::RoundCap:
return "round";
196 default:
return "???";
202 if ( str ==
"square" )
return Qt::SquareCap;
203 if ( str ==
"flat" )
return Qt::FlatCap;
204 if ( str ==
"round" )
return Qt::RoundCap;
205 return Qt::SquareCap;
212 case Qt::SquareCap:
return "square";
213 case Qt::FlatCap:
return "butt";
214 case Qt::RoundCap:
return "round";
221 if ( str ==
"square" )
return Qt::SquareCap;
222 if ( str ==
"butt" )
return Qt::FlatCap;
223 if ( str ==
"round" )
return Qt::RoundCap;
224 return Qt::SquareCap;
231 case Qt::SolidPattern :
return "solid";
232 case Qt::HorPattern :
return "horizontal";
233 case Qt::VerPattern :
return "vertical";
234 case Qt::CrossPattern :
return "cross";
235 case Qt::BDiagPattern :
return "b_diagonal";
236 case Qt::FDiagPattern :
return "f_diagonal";
237 case Qt::DiagCrossPattern :
return "diagonal_x";
238 case Qt::Dense1Pattern :
return "dense1";
239 case Qt::Dense2Pattern :
return "dense2";
240 case Qt::Dense3Pattern :
return "dense3";
241 case Qt::Dense4Pattern :
return "dense4";
242 case Qt::Dense5Pattern :
return "dense5";
243 case Qt::Dense6Pattern :
return "dense6";
244 case Qt::Dense7Pattern :
return "dense7";
245 case Qt::NoBrush :
return "no";
246 default:
return "???";
252 if ( str ==
"solid" )
return Qt::SolidPattern;
253 if ( str ==
"horizontal" )
return Qt::HorPattern;
254 if ( str ==
"vertical" )
return Qt::VerPattern;
255 if ( str ==
"cross" )
return Qt::CrossPattern;
256 if ( str ==
"b_diagonal" )
return Qt::BDiagPattern;
257 if ( str ==
"f_diagonal" )
return Qt::FDiagPattern;
258 if ( str ==
"diagonal_x" )
return Qt::DiagCrossPattern;
259 if ( str ==
"dense1" )
return Qt::Dense1Pattern;
260 if ( str ==
"dense2" )
return Qt::Dense2Pattern;
261 if ( str ==
"dense3" )
return Qt::Dense3Pattern;
262 if ( str ==
"dense4" )
return Qt::Dense4Pattern;
263 if ( str ==
"dense5" )
return Qt::Dense5Pattern;
264 if ( str ==
"dense6" )
return Qt::Dense6Pattern;
265 if ( str ==
"dense7" )
return Qt::Dense7Pattern;
266 if ( str ==
"no" )
return Qt::NoBrush;
267 return Qt::SolidPattern;
274 case Qt::CrossPattern:
return "cross";
275 case Qt::DiagCrossPattern:
return "x";
281 case Qt::HorPattern:
return "horline";
282 case Qt::VerPattern:
return "line";
283 case Qt::BDiagPattern:
return "slash";
284 case Qt::FDiagPattern:
return "backslash";
287 case Qt::Dense1Pattern:
288 case Qt::Dense2Pattern:
289 case Qt::Dense3Pattern:
290 case Qt::Dense4Pattern:
291 case Qt::Dense5Pattern:
292 case Qt::Dense6Pattern:
293 case Qt::Dense7Pattern:
303 if ( str ==
"horline" )
return Qt::HorPattern;
304 if ( str ==
"line" )
return Qt::VerPattern;
305 if ( str ==
"cross" )
return Qt::CrossPattern;
306 if ( str ==
"slash" )
return Qt::BDiagPattern;
307 if ( str ==
"backshash" )
return Qt::FDiagPattern;
308 if ( str ==
"x" )
return Qt::DiagCrossPattern;
310 if ( str.startsWith(
"brush://" ) )
318 return QString(
"%1,%2" ).arg( point.x() ).arg( point.y() );
323 QStringList lst = str.split(
',' );
324 if ( lst.count() != 2 )
325 return QPointF( 0, 0 );
326 return QPointF( lst[0].toDouble(), lst[1].toDouble() );
331 return QString(
"%1,%2" ).arg( mapUnitScale.
minScale ).arg( mapUnitScale.
maxScale );
336 QStringList lst = str.split(
',' );
337 if ( lst.count() != 2 )
363 else if ( str ==
"MapUnit" )
367 else if ( str ==
"Pixel" )
382 *scaleFactor = 0.001;
383 return "http://www.opengeospatial.org/se/units/metre";
399 if ( str ==
"http://www.opengeospatial.org/se/units/metre" )
402 *scaleFactor = 1000.0;
405 else if ( str ==
"http://www.opengeospatial.org/se/units/foot" )
408 *scaleFactor = 304.8;
415 *scaleFactor = 1 / 0.00028;
421 QString vectorString;
422 QVector<qreal>::const_iterator it = v.constBegin();
423 for ( ; it != v.constEnd(); ++it )
425 if ( it != v.constBegin() )
427 vectorString.append(
";" );
429 vectorString.append( QString::number( *it ) );
436 QVector<qreal> resultVector;
438 QStringList realList = s.split(
";" );
439 QStringList::const_iterator it = realList.constBegin();
440 for ( ; it != realList.constEnd(); ++it )
442 resultVector.append( it->toDouble() );
450 QString vectorString;
451 QVector<qreal>::const_iterator it = v.constBegin();
452 for ( ; it != v.constEnd(); ++it )
454 if ( it != v.constBegin() )
456 vectorString.append(
" " );
458 vectorString.append( QString::number( *it ) );
465 QVector<qreal> resultVector;
467 QStringList realList = s.split(
" " );
468 QStringList::const_iterator it = realList.constBegin();
469 for ( ; it != realList.constEnd(); ++it )
471 resultVector.append( it->toDouble() );
479 QString encodedValue;
481 switch ( scaleMethod )
484 encodedValue =
"diameter";
487 encodedValue =
"area";
497 if ( str ==
"diameter" )
511 if ( s.compare(
"Lighten", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Lighten;
512 if ( s.compare(
"Screen", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Screen;
513 if ( s.compare(
"Dodge", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_ColorDodge;
514 if ( s.compare(
"Addition", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Plus;
515 if ( s.compare(
"Darken", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Darken;
516 if ( s.compare(
"Multiply", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Multiply;
517 if ( s.compare(
"Burn", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_ColorBurn;
518 if ( s.compare(
"Overlay", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Overlay;
519 if ( s.compare(
"SoftLight", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_SoftLight;
520 if ( s.compare(
"HardLight", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_HardLight;
521 if ( s.compare(
"Difference", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Difference;
522 if ( s.compare(
"Subtract", Qt::CaseInsensitive ) == 0 )
return QPainter::CompositionMode_Exclusion;
523 return QPainter::CompositionMode_SourceOver;
535 QPixmap pixmap( size );
536 pixmap.fill( Qt::transparent );
538 painter.begin( &pixmap );
539 painter.setRenderHint( QPainter::Antialiasing );
554 maxBleed = layerMaxBleed > maxBleed ? layerMaxBleed : maxBleed;
562 QPixmap pixmap( size );
563 pixmap.fill( Qt::transparent );
565 painter.begin( &pixmap );
566 painter.setRenderHint( QPainter::Antialiasing );
571 return QIcon( pixmap );
581 QPixmap pixmap( size );
582 pixmap.fill( Qt::transparent );
585 painter.begin( &pixmap );
592 for (
int i = 0; i < size.width(); i++ )
594 QPen pen( ramp->
color((
double ) i / size.width() ) );
595 painter.setPen( pen );
596 painter.drawLine( i, 0, i, size.height() - 1 );
605 uchar pixDataRGB[] = { 255, 255, 255, 255,
610 QImage img( pixDataRGB, 2, 2, 8, QImage::Format_ARGB32 );
612 int width = ( rect.width() < rect.height() ) ?
613 rect.width() / 2.5 : rect.height() / 2.5;
614 QPixmap pix = QPixmap::fromImage( img.scaled( width, width ) );
617 brush.setTexture( pix );
618 painter->fillRect( rect, brush );
627 #if !defined(GEOS_VERSION_MAJOR) || !defined(GEOS_VERSION_MINOR) || \ 628 ((GEOS_VERSION_MAJOR<3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR<3))) 632 double x1 = p1.x(), y1 = p1.y(), x2 = p2.x(), y2 = p2.y();
634 if ( x1 == x2 && y1 == y2 )
638 t = ( x1 == x2 ? DBL_MAX : ( y2 - y1 ) / ( x2 - x1 ) );
642 angle = ( y2 > y1 ?
M_PI / 2 :
M_PI * 3 / 2 );
644 angle = ( x2 > x1 ? 0 :
M_PI );
646 angle = ( y2 > y1 ? atan( t ) :
M_PI + atan( t ) );
648 angle = ( y2 > y1 ?
M_PI + atan( t ) : atan( t ) );
656 return QPointF( pt.x() + dist * cos( angle ), pt.y() + dist * sin( angle ) );
663 if (( t1 == DBL_MAX && t2 == DBL_MAX ) || qAbs( atan( t1 ) - atan( t2 ) ) < 0.175 )
667 if ( t1 == DBL_MAX || t2 == DBL_MAX )
673 QPointF pSwp = p1; p1 = p2; p2 = pSwp;
674 double tSwp = t1; t1 = t2; t2 = tSwp;
682 x = (( p1.y() - p2.y() ) + t2 * p2.x() - t1 * p1.x() ) / ( t2 - t1 );
685 y = p1.y() + t1 * ( x - p1.x() );
686 return QPointF( x, y );
689 static QPolygonF makeOffsetGeometry(
const QgsPolyline& polyline )
691 int i, pointCount = polyline.count();
693 QPolygonF resultLine;
694 resultLine.resize( pointCount );
696 const QgsPoint* tempPtr = polyline.data();
698 for ( i = 0; i < pointCount; ++i, tempPtr++ )
699 resultLine[i] = QPointF( tempPtr->
x(), tempPtr->
y() );
703 static QList<QPolygonF> makeOffsetGeometry(
const QgsPolygon& polygon )
705 QList<QPolygonF> resultGeom;
706 for (
int ring = 0; ring < polygon.size(); ++ring )
707 resultGeom.append( makeOffsetGeometry( polygon[ ring ] ) );
714 QList<QPolygonF> resultLine;
716 if ( polyline.count() < 2 )
718 resultLine.append( polyline );
725 #if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \ 726 ((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3))) 728 unsigned int i, pointCount = polyline.count();
731 QPointF* tempPtr = polyline.data();
732 for ( i = 0; i < pointCount; ++i, tempPtr++ )
733 tempPolyline[i] =
QgsPoint( tempPtr->rx(), tempPtr->ry() );
738 int quadSegments = 0;
739 double mitreLimit = 2.0;
742 offsetGeom = tempGeometry->
buffer( -dist, quadSegments, GEOSBUF_CAP_FLAT, GEOSBUF_JOIN_MITRE, mitreLimit );
744 offsetGeom = tempGeometry->
offsetCurve( dist, quadSegments, GEOSBUF_JOIN_MITRE, mitreLimit );
749 tempGeometry = offsetGeom;
756 if ( dist < 0 ) std::reverse(line.begin(), line.end() );
757 resultLine.append( makeOffsetGeometry( line ) );
763 resultLine.append( makeOffsetGeometry( tempGeometry->
asPolygon() ) );
771 for (
int part = 0; part < tempMPolyline.count(); ++part )
773 resultLine.append( makeOffsetGeometry( tempMPolyline[ part ] ) );
782 for (
int part = 0; part < tempMPolygon.count(); ++part )
784 resultLine.append( makeOffsetGeometry( tempMPolygon[ part ] ) );
794 resultLine.append( polyline );
799 double angle = 0.0, t_new, t_old = 0;
800 QPointF pt_old, pt_new;
801 QPointF p1 = polyline[0], p2;
802 bool first_point =
true;
804 for (
int i = 1; i < polyline.count(); i++ )
808 if ( !
lineInfo( p1, p2, angle, t_new ) )
818 if ( !pt_tmp.isNull() )
822 newLine.append( pt_new );
832 newLine.append( pt_new );
834 resultLine.append( newLine );
840 QList<QPolygonF>
offsetLine( QPolygonF polyline,
double dist )
843 int pointCount = polyline.count();
845 if ( pointCount > 3 && polyline[ 0 ].x() == polyline[ pointCount - 1 ].x() && polyline[ 0 ].y() == polyline[ pointCount - 1 ].y() )
849 else if ( pointCount > 1 )
853 return offsetLine( polyline, dist, geometryType );
862 QDomNode layerNode = element.firstChild();
864 while ( !layerNode.isNull() )
866 QDomElement e = layerNode.toElement();
869 if ( e.tagName() !=
"layer" )
880 QDomElement s = e.firstChildElement(
"symbol" );
887 QgsDebugMsg(
"symbol layer refused subsymbol: " + s.attribute(
"name" ) );
890 layers.append( layer );
894 layerNode = layerNode.nextSibling();
897 if ( layers.count() == 0 )
903 QString symbolType = element.attribute(
"type" );
906 if ( symbolType ==
"line" )
908 else if ( symbolType ==
"fill" )
910 else if ( symbolType ==
"marker" )
914 QgsDebugMsg(
"unknown symbol type " + symbolType );
918 if ( element.hasAttribute(
"outputUnit" ) )
922 if ( element.hasAttribute((
"mapUnitScale" ) ) )
925 mapUnitScale.
minScale = element.attribute(
"mapUnitMinScale",
"0.0" ).toDouble();
926 mapUnitScale.
maxScale = element.attribute(
"mapUnitMaxScale",
"0.0" ).toDouble();
929 symbol->
setAlpha( element.attribute(
"alpha",
"1.0" ).toDouble() );
936 QString layerClass = element.attribute(
"class" );
937 bool locked = element.attribute(
"locked" ).toInt();
938 int pass = element.attribute(
"pass" ).toInt();
972 QDomElement symEl = doc.createElement(
"symbol" );
974 symEl.setAttribute(
"name", name );
975 symEl.setAttribute(
"alpha", QString::number( symbol->
alpha() ) );
982 QDomElement layerEl = doc.createElement(
"layer" );
983 layerEl.setAttribute(
"class", layer->
layerType() );
984 layerEl.setAttribute(
"locked", layer->
isLocked() );
989 QString subname = QString(
"@%1@%2" ).arg( name ).arg( i );
991 layerEl.appendChild( subEl );
993 symEl.appendChild( layerEl );
1006 if ( element.isNull() )
1011 QString symbolizerName = element.localName();
1013 if ( symbolizerName ==
"PointSymbolizer" )
1016 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1017 if ( graphicElem.isNull() )
1019 QgsDebugMsg(
"Graphic element not found in PointSymbolizer" );
1055 if ( symbolizerName ==
"LineSymbolizer" )
1058 QDomElement strokeElem = element.firstChildElement(
"Stroke" );
1059 if ( strokeElem.isNull() )
1061 QgsDebugMsg(
"Stroke element not found in LineSymbolizer" );
1089 if ( symbolizerName ==
"PolygonSymbolizer" )
1092 QDomElement fillElem = element.firstChildElement(
"Fill" );
1093 QDomElement strokeElem = element.firstChildElement(
"Stroke" );
1094 if ( fillElem.isNull() && strokeElem.isNull() )
1096 QgsDebugMsg(
"neither Fill nor Stroke element not found in PolygonSymbolizer" );
1150 QDomElement fillElem = element.firstChildElement(
"Fill" );
1151 if ( fillElem.isNull() )
1173 QDomElement strokeElem = element.firstChildElement(
"Stroke" );
1174 if ( strokeElem.isNull() )
1192 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1193 if ( graphicElem.isNull() )
1215 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1216 if ( graphicElem.isNull() )
1219 QDomElement externalGraphicElem = graphicElem.firstChildElement(
"ExternalGraphic" );
1220 if ( externalGraphicElem.isNull() )
1224 QDomElement formatElem = externalGraphicElem.firstChildElement(
"Format" );
1225 if ( formatElem.isNull() )
1228 QString format = formatElem.firstChild().nodeValue();
1229 if ( format !=
"image/svg+xml" )
1231 QgsDebugMsg(
"unsupported External Graphic format found: " + format );
1236 QDomElement onlineResourceElem = externalGraphicElem.firstChildElement(
"OnlineResource" );
1237 QDomElement inlineContentElem = externalGraphicElem.firstChildElement(
"InlineContent" );
1238 if ( !onlineResourceElem.isNull() )
1243 else if ( !inlineContentElem.isNull() )
1256 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1257 if ( graphicElem.isNull() )
1260 QDomElement markElem = graphicElem.firstChildElement(
"Mark" );
1261 if ( markElem.isNull() )
1264 QDomElement wellKnownNameElem = markElem.firstChildElement(
"WellKnownName" );
1265 if ( wellKnownNameElem.isNull() )
1274 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1275 if ( graphicElem.isNull() )
1278 QDomElement markElem = graphicElem.firstChildElement(
"Mark" );
1279 if ( markElem.isNull() )
1283 QDomElement formatElem = markElem.firstChildElement(
"Format" );
1284 if ( formatElem.isNull() )
1287 QString format = formatElem.firstChild().nodeValue();
1288 if ( format !=
"ttf" )
1290 QgsDebugMsg(
"unsupported Graphic Mark format found: " + format );
1295 QDomElement onlineResourceElem = markElem.firstChildElement(
"OnlineResource" );
1296 QDomElement inlineContentElem = markElem.firstChildElement(
"InlineContent" );
1297 if ( !onlineResourceElem.isNull() )
1300 QDomElement markIndexElem = markElem.firstChildElement(
"MarkIndex" );
1301 if ( !markIndexElem.isNull() )
1304 else if ( !inlineContentElem.isNull() )
1319 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1320 if ( graphicElem.isNull() )
1324 for ( QgsStringMap::iterator it = vendorOptions.begin(); it != vendorOptions.end(); ++it )
1326 if ( it.key() ==
"widthHeightFactor" )
1337 QDomElement strokeElem = element.firstChildElement(
"Stroke" );
1338 if ( strokeElem.isNull() )
1341 QDomElement graphicStrokeElem = strokeElem.firstChildElement(
"GraphicStroke" );
1342 if ( graphicStrokeElem.isNull() )
1350 QDomElement fillElem = element.firstChildElement(
"Fill" );
1351 if ( fillElem.isNull() )
1354 QDomElement graphicFillElem = fillElem.firstChildElement(
"GraphicFill" );
1355 if ( graphicFillElem.isNull() )
1358 QDomElement graphicElem = graphicFillElem.firstChildElement(
"Graphic" );
1359 if ( graphicElem.isNull() )
1365 QColor fillColor, borderColor;
1366 double size, borderWidth;
1367 Qt::PenStyle borderStyle;
1368 if ( !
wellKnownMarkerFromSld( graphicElem, name, fillColor, borderColor, borderStyle, borderWidth, size ) )
1371 if ( name !=
"horline" )
1379 double angle = angleFunc.toDouble( &ok );
1380 if ( !ok || angle == 0 )
1388 Q_UNUSED( element );
1394 QDomElement fillElem = element.firstChildElement(
"Fill" );
1395 if ( fillElem.isNull() )
1398 QDomElement graphicFillElem = fillElem.firstChildElement(
"GraphicFill" );
1399 if ( graphicFillElem.isNull() )
1419 QDomElement fillElem = element.firstChildElement(
"Fill" );
1420 QDomElement strokeElem = element.firstChildElement(
"Stroke" );
1424 bool validFill =
false, validBorder =
false;
1429 Qt::BrushStyle fillStyle;
1431 if (
fillFromSld( fillElem, fillStyle, fillColor ) )
1437 Qt::PenStyle borderStyle;
1438 double borderWidth = 1.0, dashOffset = 0.0;
1439 QVector<qreal> customDashPattern;
1441 if (
lineFromSld( strokeElem, borderStyle, borderColor, borderWidth,
1442 0, 0, &customDashPattern, &dashOffset ) )
1445 if ( validFill || validBorder )
1448 map[
"name"] =
"square";
1449 map[
"color"] =
encodeColor( validFill ? fillColor : Qt::transparent );
1450 map[
"color_border"] =
encodeColor( validBorder ? borderColor : Qt::transparent );
1451 map[
"size"] = QString::number( 6 );
1452 map[
"angle"] = QString::number( 0 );
1460 bool validFill =
false, validBorder =
false;
1463 QString name, format;
1465 QColor fillColor, borderColor;
1466 double borderWidth = 1.0, size = 0.0,
angle = 0.0;
1467 QPointF anchor, offset;
1470 QDomElement graphicFillElem = fillElem.firstChildElement(
"GraphicFill" );
1471 if ( !graphicFillElem.isNull() )
1474 QDomElement graphicElem = graphicFillElem.firstChildElement(
"Graphic" );
1475 if ( !graphicElem.isNull() )
1481 QDomElement graphicChildElem = graphicElem.firstChildElement();
1482 while ( !graphicChildElem.isNull() )
1484 if ( graphicChildElem.localName() ==
"Mark" )
1487 QDomElement wellKnownNameElem = graphicChildElem.firstChildElement(
"WellKnownName" );
1488 if ( !wellKnownNameElem.isNull() )
1490 name = wellKnownNameElem.firstChild().nodeValue();
1496 if ( graphicChildElem.localName() ==
"ExternalGraphic" || graphicChildElem.localName() ==
"Mark" )
1499 QDomElement formatElem = graphicChildElem.firstChildElement(
"Format" );
1500 if ( formatElem.isNull() )
1503 format = formatElem.firstChild().nodeValue();
1507 if ( graphicChildElem.localName() ==
"ExternalGraphic" && format !=
"image/svg+xml" )
1512 if ( graphicChildElem.localName() ==
"Mark" && format !=
"ttf" )
1516 QDomElement onlineResourceElem = graphicChildElem.firstChildElement(
"OnlineResource" );
1517 QDomElement inlineContentElem = graphicChildElem.firstChildElement(
"InlineContent" );
1519 if ( !onlineResourceElem.isNull() )
1521 name = onlineResourceElem.attributeNS(
"http://www.w3.org/1999/xlink",
"href" );
1523 if ( graphicChildElem.localName() ==
"Mark" && format ==
"ttf" )
1526 if ( name.startsWith(
"ttf://" ) )
1527 name = name.mid( 6 );
1530 QDomElement markIndexElem = graphicChildElem.firstChildElement(
"MarkIndex" );
1531 if ( markIndexElem.isNull() )
1535 int v = markIndexElem.firstChild().nodeValue().toInt( &ok );
1546 else if ( !inlineContentElem.isNull() )
1556 if ( graphicChildElem.localName() ==
"Mark" )
1565 if ( found && graphicChildElem.localName() ==
"Mark" )
1572 Qt::BrushStyle markFillStyle;
1574 QDomElement markFillElem = graphicChildElem.firstChildElement(
"Fill" );
1575 if (
fillFromSld( markFillElem, markFillStyle, fillColor ) )
1580 Qt::PenStyle borderStyle;
1581 double borderWidth = 1.0, dashOffset = 0.0;
1582 QVector<qreal> customDashPattern;
1584 QDomElement markStrokeElem = graphicChildElem.firstChildElement(
"Stroke" );
1585 if (
lineFromSld( markStrokeElem, borderStyle, borderColor, borderWidth,
1586 0, 0, &customDashPattern, &dashOffset ) )
1593 QDomElement opacityElem = graphicElem.firstChildElement(
"Opacity" );
1594 if ( !opacityElem.isNull() )
1595 fillColor.setAlpha(
decodeSldAlpha( opacityElem.firstChild().nodeValue() ) );
1597 QDomElement sizeElem = graphicElem.firstChildElement(
"Size" );
1598 if ( !sizeElem.isNull() )
1601 double v = sizeElem.firstChild().nodeValue().toDouble( &ok );
1610 double v = angleFunc.toDouble( &ok );
1620 if ( validFill || validBorder )
1622 if ( format ==
"image/svg+xml" )
1626 map[
"fill"] = fillColor.name();
1627 map[
"outline"] = borderColor.name();
1628 map[
"outline-width"] = QString::number( borderWidth );
1630 map[
"size"] = QString::number( size );
1632 map[
"angle"] = QString::number(
angle );
1633 if ( !offset.isNull() )
1637 else if ( format ==
"ttf" )
1641 map[
"chr"] = markIndex;
1642 map[
"color"] =
encodeColor( validFill ? fillColor : Qt::transparent );
1644 map[
"size"] = QString::number( size );
1646 map[
"angle"] = QString::number(
angle );
1647 if ( !offset.isNull() )
1654 if ( layers.isEmpty() )
1657 layerList << layers;
1664 QString patternName;
1665 switch ( brushStyle )
1670 case Qt::SolidPattern:
1671 if ( color.isValid() )
1674 if ( color.alpha() < 255 )
1679 case Qt::CrossPattern:
1680 case Qt::DiagCrossPattern:
1681 case Qt::HorPattern:
1682 case Qt::VerPattern:
1683 case Qt::BDiagPattern:
1684 case Qt::FDiagPattern:
1685 case Qt::Dense1Pattern:
1686 case Qt::Dense2Pattern:
1687 case Qt::Dense3Pattern:
1688 case Qt::Dense4Pattern:
1689 case Qt::Dense5Pattern:
1690 case Qt::Dense6Pattern:
1691 case Qt::Dense7Pattern:
1696 element.appendChild( doc.createComment( QString(
"Qt::BrushStyle '%1'' not supported yet" ).arg( brushStyle ) ) );
1700 QDomElement graphicFillElem = doc.createElement(
"se:GraphicFill" );
1701 element.appendChild( graphicFillElem );
1703 QDomElement graphicElem = doc.createElement(
"se:Graphic" );
1704 graphicFillElem.appendChild( graphicElem );
1706 QColor fillColor = patternName.startsWith(
"brush://" ) ? color : QColor();
1707 QColor borderColor = !patternName.startsWith(
"brush://" ) ? color : QColor();
1710 wellKnownMarkerToSld( doc, graphicElem, patternName, fillColor, borderColor, Qt::SolidLine, -1, -1 );
1717 brushStyle = Qt::SolidPattern;
1718 color = QColor(
"#808080" );
1720 if ( element.isNull() )
1722 brushStyle = Qt::NoBrush;
1727 QDomElement graphicFillElem = element.firstChildElement(
"GraphicFill" );
1729 if ( graphicFillElem.isNull() )
1732 for ( QgsStringMap::iterator it = svgParams.begin(); it != svgParams.end(); ++it )
1734 QgsDebugMsg( QString(
"found SvgParameter %1: %2" ).arg( it.key() ).arg( it.value() ) );
1736 if ( it.key() ==
"fill" )
1737 color = QColor( it.value() );
1738 else if ( it.key() ==
"fill-opacity" )
1744 QDomElement graphicElem = graphicFillElem.firstChildElement(
"Graphic" );
1745 if ( graphicElem.isNull() )
1748 QString patternName =
"square";
1749 QColor fillColor, borderColor;
1750 double borderWidth, size;
1751 Qt::PenStyle borderStyle;
1752 if ( !
wellKnownMarkerFromSld( graphicElem, patternName, fillColor, borderColor, borderStyle, borderWidth, size ) )
1756 if ( brushStyle == Qt::NoBrush )
1759 QColor c = patternName.startsWith(
"brush://" ) ? fillColor : borderColor;
1768 Qt::PenStyle penStyle, QColor color,
double width,
1769 const Qt::PenJoinStyle *penJoinStyle,
const Qt::PenCapStyle *penCapStyle,
1770 const QVector<qreal> *customDashPattern,
double dashOffset )
1772 QVector<qreal> dashPattern;
1773 const QVector<qreal> *pattern = &dashPattern;
1775 if ( penStyle == Qt::CustomDashLine && !customDashPattern )
1777 element.appendChild( doc.createComment(
"WARNING: Custom dash pattern required but not provided. Using default dash pattern." ) );
1778 penStyle = Qt::DashLine;
1790 dashPattern.push_back( 4.0 );
1791 dashPattern.push_back( 2.0 );
1794 dashPattern.push_back( 1.0 );
1795 dashPattern.push_back( 2.0 );
1797 case Qt::DashDotLine:
1798 dashPattern.push_back( 4.0 );
1799 dashPattern.push_back( 2.0 );
1800 dashPattern.push_back( 1.0 );
1801 dashPattern.push_back( 2.0 );
1803 case Qt::DashDotDotLine:
1804 dashPattern.push_back( 4.0 );
1805 dashPattern.push_back( 2.0 );
1806 dashPattern.push_back( 1.0 );
1807 dashPattern.push_back( 2.0 );
1808 dashPattern.push_back( 1.0 );
1809 dashPattern.push_back( 2.0 );
1812 case Qt::CustomDashLine:
1813 Q_ASSERT( customDashPattern );
1814 pattern = customDashPattern;
1818 element.appendChild( doc.createComment( QString(
"Qt::BrushStyle '%1'' not supported yet" ).arg( penStyle ) ) );
1822 if ( color.isValid() )
1825 if ( color.alpha() < 255 )
1835 if ( pattern->size() > 0 )
1845 Qt::PenStyle &penStyle, QColor &color,
double &width,
1846 Qt::PenJoinStyle *penJoinStyle, Qt::PenCapStyle *penCapStyle,
1847 QVector<qreal> *customDashPattern,
double *dashOffset )
1851 penStyle = Qt::SolidLine;
1852 color = QColor(
"#000000" );
1855 *penJoinStyle = Qt::BevelJoin;
1857 *penCapStyle = Qt::SquareCap;
1858 if ( customDashPattern )
1859 customDashPattern->clear();
1863 if ( element.isNull() )
1865 penStyle = Qt::NoPen;
1871 for ( QgsStringMap::iterator it = svgParams.begin(); it != svgParams.end(); ++it )
1873 QgsDebugMsg( QString(
"found SvgParameter %1: %2" ).arg( it.key() ).arg( it.value() ) );
1875 if ( it.key() ==
"stroke" )
1877 color = QColor( it.value() );
1879 else if ( it.key() ==
"stroke-opacity" )
1883 else if ( it.key() ==
"stroke-width" )
1886 double w = it.value().toDouble( &ok );
1890 else if ( it.key() ==
"stroke-linejoin" && penJoinStyle )
1894 else if ( it.key() ==
"stroke-linecap" && penCapStyle )
1898 else if ( it.key() ==
"stroke-dasharray" )
1901 if ( dashPattern.size() > 0 )
1905 bool dashPatternFound =
false;
1907 if ( dashPattern.count() == 2 )
1909 if ( dashPattern.at( 0 ) == 4.0 &&
1910 dashPattern.at( 1 ) == 2.0 )
1912 penStyle = Qt::DashLine;
1913 dashPatternFound =
true;
1915 else if ( dashPattern.at( 0 ) == 1.0 &&
1916 dashPattern.at( 1 ) == 2.0 )
1918 penStyle = Qt::DotLine;
1919 dashPatternFound =
true;
1922 else if ( dashPattern.count() == 4 )
1924 if ( dashPattern.at( 0 ) == 4.0 &&
1925 dashPattern.at( 1 ) == 2.0 &&
1926 dashPattern.at( 2 ) == 1.0 &&
1927 dashPattern.at( 3 ) == 2.0 )
1929 penStyle = Qt::DashDotLine;
1930 dashPatternFound =
true;
1933 else if ( dashPattern.count() == 6 )
1935 if ( dashPattern.at( 0 ) == 4.0 &&
1936 dashPattern.at( 1 ) == 2.0 &&
1937 dashPattern.at( 2 ) == 1.0 &&
1938 dashPattern.at( 3 ) == 2.0 &&
1939 dashPattern.at( 4 ) == 1.0 &&
1940 dashPattern.at( 5 ) == 2.0 )
1942 penStyle = Qt::DashDotDotLine;
1943 dashPatternFound =
true;
1948 if ( !dashPatternFound )
1950 if ( customDashPattern )
1952 penStyle = Qt::CustomDashLine;
1953 *customDashPattern = dashPattern;
1957 QgsDebugMsg(
"custom dash pattern required but not provided. Using default dash pattern." );
1958 penStyle = Qt::DashLine;
1963 else if ( it.key() ==
"stroke-dashoffset" && dashOffset )
1966 double d = it.value().toDouble( &ok );
1976 QString path, QString mime,
1977 QColor color,
double size )
1979 QDomElement externalGraphicElem = doc.createElement(
"se:ExternalGraphic" );
1980 element.appendChild( externalGraphicElem );
1989 QDomElement sizeElem = doc.createElement(
"se:Size" );
1990 sizeElem.appendChild( doc.createTextNode( QString::number( size ) ) );
1991 element.appendChild( sizeElem );
1996 QString &path, QString &mime,
1997 QColor &color,
double &size )
2002 QDomElement externalGraphicElem = element.firstChildElement(
"ExternalGraphic" );
2003 if ( externalGraphicElem.isNull() )
2008 QDomElement sizeElem = element.firstChildElement(
"Size" );
2009 if ( !sizeElem.isNull() )
2012 double s = sizeElem.firstChild().nodeValue().toDouble( &ok );
2021 QString path, QString format,
int *markIndex,
2022 QColor color,
double size )
2024 QDomElement markElem = doc.createElement(
"se:Mark" );
2025 element.appendChild( markElem );
2031 QDomElement markIndexElem = doc.createElement(
"se:MarkIndex" );
2032 markIndexElem.appendChild( doc.createTextNode( QString::number( *markIndex ) ) );
2033 markElem.appendChild( markIndexElem );
2037 QDomElement fillElem = doc.createElement(
"se:Fill" );
2038 fillToSld( doc, fillElem, Qt::SolidPattern, color );
2039 markElem.appendChild( fillElem );
2044 QDomElement sizeElem = doc.createElement(
"se:Size" );
2045 sizeElem.appendChild( doc.createTextNode( QString::number( size ) ) );
2046 element.appendChild( sizeElem );
2051 QString &path, QString &format,
int &markIndex,
2052 QColor &color,
double &size )
2060 QDomElement markElem = element.firstChildElement(
"Mark" );
2061 if ( markElem.isNull() )
2066 QDomElement markIndexElem = markElem.firstChildElement(
"MarkIndex" );
2067 if ( !markIndexElem.isNull() )
2070 int i = markIndexElem.firstChild().nodeValue().toInt( &ok );
2076 QDomElement fillElem = markElem.firstChildElement(
"Fill" );
2077 Qt::BrushStyle b = Qt::SolidPattern;
2082 QDomElement sizeElem = element.firstChildElement(
"Size" );
2083 if ( !sizeElem.isNull() )
2086 double s = sizeElem.firstChild().nodeValue().toDouble( &ok );
2095 QString name, QColor color, QColor borderColor,
2096 double borderWidth,
double size )
2098 wellKnownMarkerToSld( doc, element, name, color, borderColor, Qt::SolidLine, borderWidth, size );
2102 QString name, QColor color, QColor borderColor, Qt::PenStyle borderStyle,
2103 double borderWidth,
double size )
2105 QDomElement markElem = doc.createElement(
"se:Mark" );
2106 element.appendChild( markElem );
2108 QDomElement wellKnownNameElem = doc.createElement(
"se:WellKnownName" );
2109 wellKnownNameElem.appendChild( doc.createTextNode( name ) );
2110 markElem.appendChild( wellKnownNameElem );
2113 if ( color.isValid() )
2115 QDomElement fillElem = doc.createElement(
"se:Fill" );
2116 fillToSld( doc, fillElem, Qt::SolidPattern, color );
2117 markElem.appendChild( fillElem );
2121 if ( borderColor.isValid() )
2123 QDomElement strokeElem = doc.createElement(
"se:Stroke" );
2124 lineToSld( doc, strokeElem, borderStyle, borderColor, borderWidth );
2125 markElem.appendChild( strokeElem );
2131 QDomElement sizeElem = doc.createElement(
"se:Size" );
2132 sizeElem.appendChild( doc.createTextNode( QString::number( size ) ) );
2133 element.appendChild( sizeElem );
2138 QString &name, QColor &color, QColor &borderColor,
2139 double &borderWidth,
double &size )
2141 Qt::PenStyle borderStyle;
2146 QString &name, QColor &color, QColor &borderColor, Qt::PenStyle &borderStyle,
2147 double &borderWidth,
double &size )
2153 borderColor = QColor(
"#000000" );
2157 QDomElement markElem = element.firstChildElement(
"Mark" );
2158 if ( markElem.isNull() )
2161 QDomElement wellKnownNameElem = markElem.firstChildElement(
"WellKnownName" );
2162 if ( !wellKnownNameElem.isNull() )
2164 name = wellKnownNameElem.firstChild().nodeValue();
2165 QgsDebugMsg(
"found Mark with well known name: " + name );
2169 QDomElement fillElem = markElem.firstChildElement(
"Fill" );
2170 Qt::BrushStyle b = Qt::SolidPattern;
2175 QDomElement strokeElem = markElem.firstChildElement(
"Stroke" );
2176 lineFromSld( strokeElem, borderStyle, borderColor, borderWidth );
2180 QDomElement sizeElem = element.firstChildElement(
"Size" );
2181 if ( !sizeElem.isNull() )
2184 double s = sizeElem.firstChild().nodeValue().toDouble( &ok );
2194 if ( !rotationFunc.isEmpty() )
2196 QDomElement rotationElem = doc.createElement(
"se:Rotation" );
2198 element.appendChild( rotationElem );
2204 QDomElement rotationElem = element.firstChildElement(
"Rotation" );
2205 if ( !rotationElem.isNull() )
2215 if ( !alphaFunc.isEmpty() )
2217 QDomElement opacityElem = doc.createElement(
"se:Opacity" );
2219 element.appendChild( opacityElem );
2225 QDomElement opacityElem = element.firstChildElement(
"Opacity" );
2226 if ( !opacityElem.isNull() )
2235 if ( offset.isNull() )
2238 QDomElement displacementElem = doc.createElement(
"se:Displacement" );
2239 element.appendChild( displacementElem );
2241 QDomElement dispXElem = doc.createElement(
"se:DisplacementX" );
2242 dispXElem.appendChild( doc.createTextNode( QString::number( offset.x() ) ) );
2244 QDomElement dispYElem = doc.createElement(
"se:DisplacementY" );
2245 dispYElem.appendChild( doc.createTextNode( QString::number( offset.y() ) ) );
2247 displacementElem.appendChild( dispXElem );
2248 displacementElem.appendChild( dispYElem );
2253 offset = QPointF( 0, 0 );
2255 QDomElement displacementElem = element.firstChildElement(
"Displacement" );
2256 if ( displacementElem.isNull() )
2259 QDomElement dispXElem = displacementElem.firstChildElement(
"DisplacementX" );
2260 if ( !dispXElem.isNull() )
2263 double offsetX = dispXElem.firstChild().nodeValue().toDouble( &ok );
2265 offset.setX( offsetX );
2268 QDomElement dispYElem = displacementElem.firstChildElement(
"DisplacementY" );
2269 if ( !dispYElem.isNull() )
2272 double offsetY = dispYElem.firstChild().nodeValue().toDouble( &ok );
2274 offset.setY( offsetY );
2281 QString label, QFont font,
2282 QColor color,
double size )
2284 QDomElement labelElem = doc.createElement(
"se:Label" );
2285 labelElem.appendChild( doc.createTextNode( label ) );
2286 element.appendChild( labelElem );
2288 QDomElement fontElem = doc.createElement(
"se:Font" );
2289 element.appendChild( fontElem );
2293 fontElem.appendChild( createSldParameterElement( doc,
"font-style",
encodeSldFontStyle( font.style() ) ) );
2294 fontElem.appendChild( createSldParameterElement( doc,
"font-weight",
encodeSldFontWeight( font.weight() ) ) );
2299 if ( color.isValid() )
2301 QDomElement fillElem = doc.createElement(
"Fill" );
2302 fillToSld( doc, fillElem, Qt::SolidPattern, color );
2303 element.appendChild( fillElem );
2308 Qt::PenJoinStyle joinStyle,
2309 Qt::PenCapStyle capStyle,
2311 const QVector<qreal>* dashPattern )
2314 penStyle.append(
"PEN(" );
2315 penStyle.append(
"c:" );
2316 penStyle.append( c.name() );
2317 penStyle.append(
",w:" );
2319 penStyle.append( QString::number( width * mmScaleFactor ) );
2320 penStyle.append(
"mm" );
2323 if ( dashPattern && dashPattern->size() > 0 )
2325 penStyle.append(
",p:\"" );
2326 QVector<qreal>::const_iterator pIt = dashPattern->constBegin();
2327 for ( ; pIt != dashPattern->constEnd(); ++pIt )
2329 if ( pIt != dashPattern->constBegin() )
2331 penStyle.append(
" " );
2333 penStyle.append( QString::number( *pIt * mapUnitScaleFactor ) );
2334 penStyle.append(
"g" );
2336 penStyle.append(
"\"" );
2340 penStyle.append(
",cap:" );
2344 penStyle.append(
"p" );
2347 penStyle.append(
"r" );
2351 penStyle.append(
"b" );
2355 penStyle.append(
",j:" );
2356 switch ( joinStyle )
2359 penStyle.append(
"b" );
2362 penStyle.append(
"r" );
2366 penStyle.append(
"m" );
2372 penStyle.append(
",dp:" );
2373 penStyle.append( QString::number( offset * mapUnitScaleFactor ) );
2374 penStyle.append(
"g" );
2377 penStyle.append(
")" );
2384 brushStyle.append(
"BRUSH(" );
2385 brushStyle.append(
"fc:" );
2386 brushStyle.append( fillColor.name() );
2387 brushStyle.append(
")" );
2393 if ( geomFunc.isEmpty() )
2396 QDomElement geometryElem = doc.createElement(
"Geometry" );
2397 element.appendChild( geometryElem );
2427 QDomElement geometryElem = element.firstChildElement(
"Geometry" );
2428 if ( geometryElem.isNull() )
2440 element.appendChild( doc.createComment(
"Parser Error: " + expr.
parserErrorString() +
" - Expression was: " + function ) );
2444 if ( !filterElem.isNull() )
2445 element.appendChild( filterElem );
2451 QDomElement elem = element;
2452 if ( element.tagName() !=
"Filter" )
2454 QDomNodeList filterNodes = element.elementsByTagName(
"Filter" );
2455 if ( filterNodes.size() > 0 )
2457 elem = filterNodes.at( 0 ).toElement();
2461 if ( elem.isNull() )
2486 QString path, QString format )
2490 QDomElement onlineResourceElem = doc.createElement(
"se:OnlineResource" );
2491 onlineResourceElem.setAttribute(
"xlink:type",
"simple" );
2492 onlineResourceElem.setAttribute(
"xlink:href", url );
2493 element.appendChild( onlineResourceElem );
2495 QDomElement formatElem = doc.createElement(
"se:Format" );
2496 formatElem.appendChild( doc.createTextNode( format ) );
2497 element.appendChild( formatElem );
2504 QDomElement onlineResourceElem = element.firstChildElement(
"OnlineResource" );
2505 if ( onlineResourceElem.isNull() )
2508 path = onlineResourceElem.attributeNS(
"http://www.w3.org/1999/xlink",
"href" );
2510 QDomElement formatElem = element.firstChildElement(
"Format" );
2511 if ( formatElem.isNull() )
2514 format = formatElem.firstChild().nodeValue();
2521 QDomElement nodeElem = doc.createElement(
"se:SvgParameter" );
2522 nodeElem.setAttribute(
"name", name );
2523 nodeElem.appendChild( doc.createTextNode( value ) );
2531 QDomElement paramElem = element.firstChildElement();
2532 while ( !paramElem.isNull() )
2534 if ( paramElem.localName() ==
"SvgParameter" || paramElem.localName() ==
"CssParameter" )
2536 QString name = paramElem.attribute(
"name" );
2537 QString value = paramElem.firstChild().nodeValue();
2539 if ( !name.isEmpty() && !value.isEmpty() )
2540 params[ name ] = value;
2543 paramElem = paramElem.nextSiblingElement();
2551 QDomElement nodeElem = doc.createElement(
"VendorOption" );
2552 nodeElem.setAttribute(
"name", name );
2553 nodeElem.appendChild( doc.createTextNode( value ) );
2561 QDomElement paramElem = element.firstChildElement(
"VendorOption" );
2562 while ( !paramElem.isNull() )
2564 QString name = paramElem.attribute(
"name" );
2565 QString value = paramElem.firstChild().nodeValue();
2567 if ( !name.isEmpty() && !value.isEmpty() )
2568 params[ name ] = value;
2570 paramElem = paramElem.nextSiblingElement(
"VendorOption" );
2580 QDomElement e = element.firstChildElement();
2581 while ( !e.isNull() )
2583 if ( e.tagName() !=
"prop" )
2589 QString propKey = e.attribute(
"k" );
2590 QString propValue = e.attribute(
"v" );
2591 props[propKey] = propValue;
2593 e = e.nextSiblingElement();
2601 for ( QgsStringMap::iterator it = props.begin(); it != props.end(); ++it )
2603 QDomElement propEl = doc.createElement(
"prop" );
2604 propEl.setAttribute(
"k", it.key() );
2605 propEl.setAttribute(
"v", it.value() );
2606 element.appendChild( propEl );
2615 QDomElement e = element.firstChildElement();
2617 while ( !e.isNull() )
2619 if ( e.tagName() ==
"symbol" )
2622 if ( symbol != NULL )
2623 symbols.insert( e.attribute(
"name" ), symbol );
2629 e = e.nextSiblingElement();
2636 QStringList subsymbols;
2638 for ( QMap<QString, QgsSymbolV2*>::iterator it = symbols.begin(); it != symbols.end(); ++it )
2640 if ( it.key()[0] !=
'@' )
2644 subsymbols.append( it.key() );
2646 QStringList parts = it.key().split(
"@" );
2647 if ( parts.count() < 3 )
2649 QgsDebugMsg(
"found subsymbol with invalid name: " + it.key() );
2653 QString symname = parts[1];
2654 int symlayer = parts[2].toInt();
2656 if ( !symbols.contains( symname ) )
2658 QgsDebugMsg(
"subsymbol references invalid symbol: " + symname );
2666 QgsDebugMsg(
"subsymbol references invalid symbol layer: " + QString::number( symlayer ) );
2675 QgsDebugMsg(
"symbol layer refused subsymbol: " + it.key() );
2682 for (
int i = 0; i < subsymbols.count(); i++ )
2683 symbols.take( subsymbols[i] );
2690 QDomElement symbolsElem = doc.createElement( tagName );
2693 for ( QMap<QString, QgsSymbolV2*>::iterator its = symbols.begin(); its != symbols.end(); ++its )
2695 QDomElement symEl =
saveSymbol( its.key(), its.value(), doc );
2696 symbolsElem.appendChild( symEl );
2704 foreach ( QString name, symbols.keys() )
2706 delete symbols.value( name );
2714 QString rampType = element.attribute(
"type" );
2719 if ( rampType ==
"gradient" )
2721 else if ( rampType ==
"random" )
2723 else if ( rampType ==
"colorbrewer" )
2725 else if ( rampType ==
"cpt-city" )
2729 QgsDebugMsg(
"unknown colorramp type " + rampType );
2737 QDomElement rampEl = doc.createElement(
"colorramp" );
2738 rampEl.setAttribute(
"type", ramp->
type() );
2739 rampEl.setAttribute(
"name", name );
2747 if ( !color.isValid() )
2754 return color.name();
2759 QList<QColor> colors;
2762 QStringList components = colorStr.simplified().split( QRegExp(
"(,|\\s)" ) );
2763 QStringList::iterator it = components.begin();
2764 for ( ; it != components.end(); ++it )
2767 if ( result.isValid() )
2772 if ( colors.length() > 0 )
2778 components = colorStr.split( QRegExp(
"(,|\n)" ) );
2779 it = components.begin();
2780 for ( ; it != components.end(); ++it )
2783 if ( result.isValid() )
2788 if ( colors.length() > 0 )
2794 components = colorStr.simplified().split( QString(
" " ) );
2795 it = components.begin();
2796 for ( ; it != components.end(); ++it )
2799 if ( result.isValid() )
2804 if ( colors.length() > 0 )
2810 components = colorStr.split( QString(
"\n" ) );
2811 it = components.begin();
2812 for ( ; it != components.end(); ++it )
2815 if ( result.isValid() )
2828 QMimeData *mimeData =
new QMimeData;
2829 mimeData->setColorData( QVariant( color ) );
2830 mimeData->setText( color.name() );
2837 QColor mimeColor = mimeData->colorData().value<QColor>();
2838 if ( mimeColor.isValid() )
2847 if ( textColor.isValid() )
2861 if ( data->hasFormat(
"text/xml" ) )
2864 QByteArray encodedData = data->data(
"text/xml" );
2865 QDomDocument xmlDoc;
2866 xmlDoc.setContent( encodedData );
2868 QDomElement dragDataElem = xmlDoc.documentElement();
2869 if ( dragDataElem.tagName() ==
"ColorSchemeModelDragData" )
2871 QDomNodeList nodeList = dragDataElem.childNodes();
2872 int nChildNodes = nodeList.size();
2873 QDomElement currentElem;
2875 for (
int i = 0; i < nChildNodes; ++i )
2877 currentElem = nodeList.at( i ).toElement();
2878 if ( currentElem.isNull() )
2883 QPair< QColor, QString> namedColor;
2885 namedColor.second = currentElem.attribute(
"label",
"" );
2887 mimeColors << namedColor;
2892 if ( mimeColors.length() == 0 && data->hasFormat(
"application/x-colorobject-list" ) )
2895 QByteArray encodedData = data->data(
"application/x-colorobject-list" );
2896 QDomDocument xmlDoc;
2897 xmlDoc.setContent( encodedData );
2899 QDomNodeList colorsNodes = xmlDoc.elementsByTagName( QString(
"colors" ) );
2900 if ( colorsNodes.length() > 0 )
2902 QDomElement colorsElem = colorsNodes.at( 0 ).toElement();
2903 QDomNodeList colorNodeList = colorsElem.childNodes();
2904 int nChildNodes = colorNodeList.size();
2905 QDomElement currentElem;
2907 for (
int i = 0; i < nChildNodes; ++i )
2910 currentElem = colorNodeList.at( i ).toElement();
2911 if ( currentElem.isNull() )
2916 QDomNodeList colorNodes = currentElem.elementsByTagName( QString(
"color" ) );
2917 QDomNodeList nameNodes = currentElem.elementsByTagName( QString(
"name" ) );
2919 if ( colorNodes.length() > 0 )
2921 QDomElement colorElem = colorNodes.at( 0 ).toElement();
2923 QStringList colorParts = colorElem.text().simplified().split(
" " );
2924 if ( colorParts.length() < 3 )
2929 int red = colorParts.at( 0 ).toDouble() * 255;
2930 int green = colorParts.at( 1 ).toDouble() * 255;
2931 int blue = colorParts.at( 2 ).toDouble() * 255;
2932 QPair< QColor, QString> namedColor;
2933 namedColor.first = QColor( red, green, blue );
2934 if ( nameNodes.length() > 0 )
2936 QDomElement nameElem = nameNodes.at( 0 ).toElement();
2937 namedColor.second = nameElem.text();
2939 mimeColors << namedColor;
2945 if ( mimeColors.length() == 0 && data->hasText() )
2949 QList< QColor >::iterator it = parsedColors.begin();
2950 for ( ; it != parsedColors.end(); ++it )
2952 mimeColors << qMakePair( *it, QString() );
2956 if ( mimeColors.length() == 0 && data->hasColor() )
2959 QColor mimeColor = data->colorData().value<QColor>();
2960 if ( mimeColor.isValid() )
2962 mimeColors << qMakePair( mimeColor, QString() );
2972 QMimeData* mimeData =
new QMimeData();
2973 QDomDocument xmlDoc;
2974 QDomElement xmlRootElement = xmlDoc.createElement(
"ColorSchemeModelDragData" );
2975 xmlDoc.appendChild( xmlRootElement );
2977 QgsNamedColorList::const_iterator colorIt = colorList.constBegin();
2978 for ( ; colorIt != colorList.constEnd(); ++colorIt )
2980 QDomElement namedColor = xmlDoc.createElement(
"NamedColor" );
2982 namedColor.setAttribute(
"label", ( *colorIt ).second );
2983 xmlRootElement.appendChild( namedColor );
2985 mimeData->setData(
"text/xml", xmlDoc.toByteArray() );
2993 colorIt = colorList.constBegin();
2994 QStringList colorListString;
2995 for ( ; colorIt != colorList.constEnd(); ++colorIt )
2997 colorListString << ( *colorIt ).first.name();
2999 mimeData->setText( colorListString.join(
"\n" ) );
3002 if ( colorList.length() > 0 )
3004 mimeData->setColorData( QVariant( colorList.at( 0 ).first ) );
3012 if ( !file.open( QIODevice::ReadWrite ) )
3017 QTextStream stream( &file );
3018 stream <<
"GIMP Palette" << endl;
3019 if ( paletteName.isEmpty() )
3021 stream <<
"Name: QGIS Palette" << endl;
3025 stream <<
"Name: " << paletteName << endl;
3027 stream <<
"Columns: 4" << endl;
3028 stream <<
"#" << endl;
3030 for ( QgsNamedColorList::ConstIterator colorIt = colors.constBegin(); colorIt != colors.constEnd(); ++colorIt )
3032 QColor color = ( *colorIt ).first;
3033 if ( !color.isValid() )
3037 stream << QString(
"%1 %2 %3" ).arg( color.red(), 3 ).arg( color.green(), 3 ).arg( color.blue(), 3 );
3038 stream <<
"\t" << (( *colorIt ).second.isEmpty() ? color.name() : ( *colorIt ).second ) << endl;
3049 if ( !file.open( QIODevice::ReadOnly ) )
3052 return importedColors;
3055 QTextStream in( &file );
3057 QString line = in.readLine();
3058 if ( !line.startsWith(
"GIMP Palette" ) )
3061 return importedColors;
3065 while ( !in.atEnd() && !line.startsWith(
"Name:" ) && !line.startsWith(
"#" ) )
3067 line = in.readLine();
3069 if ( line.startsWith(
"Name:" ) )
3071 QRegExp nameRx(
"Name:\\s*(\\S.*)$" );
3072 if ( nameRx.indexIn( line ) != -1 )
3074 name = nameRx.cap( 1 );
3079 while ( !in.atEnd() && !line.startsWith(
"#" ) )
3081 line = in.readLine();
3086 return importedColors;
3090 QRegExp rx(
"^\\s*(\\d+)\\s+(\\d+)\\s+(\\d+)(\\s.*)?$" );
3091 while ( !in.atEnd() )
3093 line = in.readLine();
3094 if ( rx.indexIn( line ) == -1 )
3098 int red = rx.cap( 1 ).toInt();
3099 int green = rx.cap( 2 ).toInt();
3100 int blue = rx.cap( 3 ).toInt();
3101 QColor color = QColor( red, green, blue );
3102 if ( !color.isValid() )
3109 if ( rx.captureCount() > 3 )
3111 label = rx.cap( 4 ).simplified();
3118 importedColors << qMakePair( color, label );
3123 return importedColors;
3137 if ( QColor::isValidColor( colorStr ) )
3140 parsedColor.setNamedColor( colorStr );
3141 if ( parsedColor.isValid() )
3143 containsAlpha =
false;
3149 QRegExp hexColorAlphaRx(
"^\\s*#?([0-9a-fA-F]{6})([0-9a-fA-F]{2})\\s*$" );
3150 if ( hexColorAlphaRx.indexIn( colorStr ) != -1 )
3152 QString hexColor = hexColorAlphaRx.cap( 1 );
3153 parsedColor.setNamedColor( QString(
"#" ) + hexColor );
3155 int alphaHex = hexColorAlphaRx.cap( 2 ).toInt( &alphaOk, 16 );
3157 if ( parsedColor.isValid() && alphaOk )
3159 parsedColor.setAlpha( alphaHex );
3160 containsAlpha =
true;
3168 QRegExp hexColorRx2(
"^\\s*(?:[0-9a-fA-F]{3}){1,2}\\s*$" );
3169 if ( hexColorRx2.indexIn( colorStr ) != -1 )
3172 parsedColor.setNamedColor( QString(
"#" ) + colorStr );
3173 if ( parsedColor.isValid() )
3175 containsAlpha =
false;
3182 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*$" );
3183 if ( rgbFormatRx.indexIn( colorStr ) != -1 )
3185 int r = rgbFormatRx.cap( 1 ).toInt();
3186 int g = rgbFormatRx.cap( 2 ).toInt();
3187 int b = rgbFormatRx.cap( 3 ).toInt();
3188 parsedColor.setRgb( r, g, b );
3189 if ( parsedColor.isValid() )
3191 containsAlpha =
false;
3197 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*$" );
3198 if ( rgbPercentFormatRx.indexIn( colorStr ) != -1 )
3200 int r = qRound( rgbPercentFormatRx.cap( 1 ).toDouble() * 2.55 );
3201 int g = qRound( rgbPercentFormatRx.cap( 2 ).toDouble() * 2.55 );
3202 int b = qRound( rgbPercentFormatRx.cap( 3 ).toDouble() * 2.55 );
3203 parsedColor.setRgb( r, g, b );
3204 if ( parsedColor.isValid() )
3206 containsAlpha =
false;
3212 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*$" );
3213 if ( rgbaFormatRx.indexIn( colorStr ) != -1 )
3215 int r = rgbaFormatRx.cap( 1 ).toInt();
3216 int g = rgbaFormatRx.cap( 2 ).toInt();
3217 int b = rgbaFormatRx.cap( 3 ).toInt();
3218 int a = qRound( rgbaFormatRx.cap( 4 ).toDouble() * 255.0 );
3219 parsedColor.setRgb( r, g, b, a );
3220 if ( parsedColor.isValid() )
3222 containsAlpha =
true;
3228 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*$" );
3229 if ( rgbaPercentFormatRx.indexIn( colorStr ) != -1 )
3231 int r = qRound( rgbaPercentFormatRx.cap( 1 ).toDouble() * 2.55 );
3232 int g = qRound( rgbaPercentFormatRx.cap( 2 ).toDouble() * 2.55 );
3233 int b = qRound( rgbaPercentFormatRx.cap( 3 ).toDouble() * 2.55 );
3234 int a = qRound( rgbaPercentFormatRx.cap( 4 ).toDouble() * 255.0 );
3235 parsedColor.setRgb( r, g, b, a );
3236 if ( parsedColor.isValid() )
3238 containsAlpha =
true;
3297 if ( p && p->device() )
3316 QImage::Format format = image->format();
3317 if ( format != QImage::Format_ARGB32_Premultiplied && format != QImage::Format_ARGB32 )
3324 for (
int heightIndex = 0; heightIndex < image->height(); ++heightIndex )
3326 QRgb* scanLine = ( QRgb* )image->scanLine( heightIndex );
3327 for (
int widthIndex = 0; widthIndex < image->width(); ++widthIndex )
3329 myRgb = scanLine[widthIndex];
3330 if ( format == QImage::Format_ARGB32_Premultiplied )
3331 scanLine[widthIndex] = qRgba( alpha * qRed( myRgb ), alpha * qGreen( myRgb ), alpha * qBlue( myRgb ), alpha * qAlpha( myRgb ) );
3333 scanLine[widthIndex] = qRgba( qRed( myRgb ), qGreen( myRgb ), qBlue( myRgb ), alpha * qAlpha( myRgb ) );
3341 int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 };
3342 int alpha = ( radius < 1 ) ? 16 : ( radius > 17 ) ? 1 : tab[radius-1];
3344 if ( image.format() != QImage::Format_ARGB32_Premultiplied
3345 && image.format() != QImage::Format_RGB32 )
3347 image = image.convertToFormat( QImage::Format_ARGB32_Premultiplied );
3350 int r1 = rect.top();
3351 int r2 = rect.bottom();
3352 int c1 = rect.left();
3353 int c2 = rect.right();
3355 int bpl = image.bytesPerLine();
3363 i1 = i2 = ( QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3 );
3365 for (
int col = c1; col <= c2; col++ )
3367 p = image.scanLine( r1 ) + col * 4;
3368 for (
int i = i1; i <= i2; i++ )
3369 rgba[i] = p[i] << 4;
3372 for (
int j = r1; j < r2; j++, p += bpl )
3373 for (
int i = i1; i <= i2; i++ )
3374 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
3377 for (
int row = r1; row <= r2; row++ )
3379 p = image.scanLine( row ) + c1 * 4;
3380 for (
int i = i1; i <= i2; i++ )
3381 rgba[i] = p[i] << 4;
3384 for (
int j = c1; j < c2; j++, p += 4 )
3385 for (
int i = i1; i <= i2; i++ )
3386 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
3389 for (
int col = c1; col <= c2; col++ )
3391 p = image.scanLine( r2 ) + col * 4;
3392 for (
int i = i1; i <= i2; i++ )
3393 rgba[i] = p[i] << 4;
3396 for (
int j = r1; j < r2; j++, p -= bpl )
3397 for (
int i = i1; i <= i2; i++ )
3398 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
3401 for (
int row = r1; row <= r2; row++ )
3403 p = image.scanLine( row ) + c2 * 4;
3404 for (
int i = i1; i <= i2; i++ )
3405 rgba[i] = p[i] << 4;
3408 for (
int j = c1; j < c2; j++, p -= 4 )
3409 for (
int i = i1; i <= i2; i++ )
3410 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
3416 if ( alpha != 255 && alpha > 0 )
3420 double alphaFactor = alpha / 255.;
3421 int r = 0, g = 0, b = 0;
3422 rgb.getRgb( &r, &g, &b );
3427 rgb.setRgb( r, g, b, alpha );
3429 else if ( alpha == 0 )
3431 rgb.setRgb( 0, 0, 0, 0 );
3436 static bool _QVariantLessThan(
const QVariant& lhs,
const QVariant& rhs )
3438 switch ( lhs.type() )
3441 return lhs.toInt() < rhs.toInt();
3442 case QVariant::UInt:
3443 return lhs.toUInt() < rhs.toUInt();
3444 case QVariant::LongLong:
3445 return lhs.toLongLong() < rhs.toLongLong();
3446 case QVariant::ULongLong:
3447 return lhs.toULongLong() < rhs.toULongLong();
3448 case QVariant::Double:
3449 return lhs.toDouble() < rhs.toDouble();
3450 case QVariant::Char:
3451 return lhs.toChar() < rhs.toChar();
3452 case QVariant::Date:
3453 return lhs.toDate() < rhs.toDate();
3454 case QVariant::Time:
3455 return lhs.toTime() < rhs.toTime();
3456 case QVariant::DateTime:
3457 return lhs.toDateTime() < rhs.toDateTime();
3459 return QString::localeAwareCompare( lhs.toString(), rhs.toString() ) < 0;
3463 static bool _QVariantGreaterThan(
const QVariant& lhs,
const QVariant& rhs )
3465 return ! _QVariantLessThan( lhs, rhs );
3471 if ( order == Qt::AscendingOrder )
3485 double dx = directionPoint.x() - startPoint.x();
3486 double dy = directionPoint.y() - startPoint.y();
3487 double length = sqrt( dx * dx + dy * dy );
3488 double scaleFactor = distance / length;
3489 return QPointF( startPoint.x() + dx * scaleFactor, startPoint.y() + dy * scaleFactor );
3499 for (
int i = 0; i < svgPaths.size(); i++ )
3501 QDir dir( svgPaths[i] );
3502 foreach ( QString item, dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
3504 svgPaths.insert( i + 1, dir.path() +
"/" + item );
3507 foreach ( QString item, dir.entryList( QStringList(
"*.svg" ), QDir::Files ) )
3510 list.append( dir.path() +
"/" + item );
3522 QStringList svgPaths;
3523 svgPaths.append( directory );
3525 for (
int i = 0; i < svgPaths.size(); i++ )
3527 QDir dir( svgPaths[i] );
3528 foreach ( QString item, dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
3530 svgPaths.insert( i + 1, dir.path() +
"/" + item );
3533 foreach ( QString item, dir.entryList( QStringList(
"*.svg" ), QDir::Files ) )
3535 list.append( dir.path() +
"/" + item );
3547 if ( QFile( name ).exists() )
3548 return QFileInfo( name ).canonicalFilePath();
3551 if ( name.contains(
"://" ) )
3554 if ( url.isValid() && !url.scheme().isEmpty() )
3556 if ( url.scheme().compare(
"file", Qt::CaseInsensitive ) == 0 )
3559 name = url.toLocalFile();
3560 if ( QFile( name ).exists() )
3562 return QFileInfo( name ).canonicalFilePath();
3576 for (
int i = 0; i < svgPaths.size(); i++ )
3578 QString svgPath = svgPaths[i];
3579 if ( svgPath.endsWith( QString(
"/" ) ) )
3590 QString myLocalPath = svgPath + QDir::separator() + name;
3592 QgsDebugMsg(
"Alternative svg path: " + myLocalPath );
3593 if ( QFile( myLocalPath ).exists() )
3596 return QFileInfo( myLocalPath ).canonicalFilePath();
3601 QString alternatePath = pfi.canonicalPath() + QDir::separator() + name;
3602 if ( pfi.exists() && QFile( alternatePath ).exists() )
3605 return QFileInfo( alternatePath ).canonicalFilePath();
3612 QgsDebugMsg(
"Computed alternate path but no svg there either" );
3621 QFileInfo fi( path );
3625 path = fi.canonicalFilePath();
3629 bool isInSvgPathes =
false;
3630 for (
int i = 0; i < svgPaths.size(); i++ )
3632 QString dir = QFileInfo( svgPaths[i] ).canonicalFilePath();
3634 if ( !dir.isEmpty() && path.startsWith( dir ) )
3636 path = path.mid( dir.size() + 1 );
3637 isInSvgPathes =
true;
3642 if ( isInSvgPathes )
3651 double cx = 0, cy = 0;
3652 double area, sum = 0;
3653 for (
int i = points.count() - 1, j = 0; j < points.count(); i = j++ )
3655 const QPointF& p1 = points[i];
3656 const QPointF& p2 = points[j];
3657 area = p1.x() * p2.y() - p1.y() * p2.x();
3659 cx += ( p1.x() + p2.x() ) * area;
3660 cy += ( p1.y() + p2.y() ) * area;
3667 if ( points.count() >= 2 )
3668 return QPointF(( points[0].x() + points[1].x() ) / 2, ( points[0].y() + points[1].y() ) / 2 );
3669 else if ( points.count() == 1 )
3677 return QPointF( cx, cy );
3687 unsigned int i, pointCount = points.count();
3690 for ( i = 0; i < pointCount; ++i ) polyline[i] =
QgsPoint( points[i].x(), points[i].y() );
3697 if ( pointOnSurfaceGeom )
3700 delete pointOnSurfaceGeom;
3703 return QPointF( point.
x(), point.
y() );
3713 bool inside =
false;
3715 double x = point.x();
3716 double y = point.y();
3718 for (
int i = 0, j = points.count() - 1; i < points.count(); i++ )
3720 const QPointF& p1 = points[i];
3721 const QPointF& p2 = points[j];
3723 if ( p1.x() == x && p1.y() == y )
3726 if (( p1.y() < y && p2.y() >= y ) || ( p2.y() < y && p1.y() >= y ) )
3728 if ( p1.x() + ( y - p1.y() ) / ( p2.y() - p1.y() )*( p2.x() - p1.x() ) <= x )
3739 if ( fieldOrExpression.isEmpty() )
3758 return static_cast<const QgsExpression::NodeColumnRef*>( n )->name();
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
static QString encodeOutputUnit(QgsSymbolV2::OutputUnit unit)
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
QMap< QString, QgsSymbolV2 * > QgsSymbolV2Map
static QString encodeSldLineJoinStyle(Qt::PenJoinStyle style)
static void sortVariantList(QList< QVariant > &list, Qt::SortOrder order)
Sorts the passed list in requested order.
Class for parsing and evaluation of expressions (formerly called "search strings").
static Qt::BrushStyle decodeBrushStyle(QString str)
void setLocked(bool locked)
static QgsSymbolV2Map loadSymbols(QDomElement &element)
static Qt::PenCapStyle decodeSldLineCapStyle(QString str)
virtual NodeType nodeType() const =0
static void multiplyImageOpacity(QImage *image, qreal alpha)
Multiplies opacity of image pixel values with a (global) transparency value.
QString writePath(QString filename, QString relativeBasePath=QString::null) const
prepare a filename to save it to the project file
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
static void drawStippledBackground(QPainter *painter, QRect rect)
QgsSymbolLayerV2 * createSymbolLayer(QString name, const QgsStringMap &properties=QgsStringMap()) const
create a new instance of symbol layer given symbol layer name and properties
static QIcon colorRampPreviewIcon(QgsVectorColorRampV2 *ramp, QSize size)
virtual QString type() const =0
static QIcon symbolLayerPreviewIcon(QgsSymbolLayerV2 *layer, QgsSymbolV2::OutputUnit u, QSize size, const QgsMapUnitScale &scale=QgsMapUnitScale())
static QPixmap colorRampPreviewPixmap(QgsVectorColorRampV2 *ramp, QSize size)
static QString quotedColumnRef(QString name)
return quoted column reference (in double quotes)
static Q_DECL_DEPRECATED bool wellKnownMarkerFromSld(QDomElement &element, QString &name, QColor &color, QColor &borderColor, double &borderWidth, double &size)
static QgsVectorColorRampV2 * loadColorRamp(QDomElement &element)
static QMimeData * colorToMimeData(const QColor &color)
Creates mime data from a color.
static const QStringList svgPaths()
Returns the pathes to svg directories.
const QString expression() const
Alias for dump()
static QString encodeSldUom(QgsSymbolV2::OutputUnit unit, double *scaleFactor)
QgsMultiPolyline asMultiPolyline() const
return contents of the geometry as a multi linestring if wkbType is WKBMultiLineString, otherwise an empty list
static void createRotationElement(QDomDocument &doc, QDomElement &element, QString rotationFunc)
QVector< QgsPoint > QgsPolyline
polyline is represented as a vector of points
static QgsStringMap getVendorOptionList(QDomElement &element)
double computeMapUnitsPerPixel(const QgsRenderContext &c) const
Computes a map units per pixel scaling factor, respecting the minimum and maximum scales set for the ...
QgsPolygon asPolygon() const
return contents of the geometry as a polygon if wkbType is WKBPolygon, otherwise an empty list ...
static QString ogrFeatureStyleBrush(const QColor &fillColr)
Create ogr feature style string for brush.
static void fillToSld(QDomDocument &doc, QDomElement &element, Qt::BrushStyle brushStyle, QColor color=QColor())
static QVector< qreal > decodeRealVector(const QString &s)
static QColor colorFromMimeData(const QMimeData *data, bool &hasAlpha)
Attempts to parse mime data as a color.
static bool functionFromSldElement(QDomElement &element, QString &function)
static QString encodeSldFontStyle(QFont::Style style)
QList< QPair< QColor, QString > > QgsNamedColorList
List of colors paired with a friendly display name identifying the color.
static QPointF decodePoint(QString str)
static bool externalGraphicFromSld(QDomElement &element, QString &path, QString &mime, QColor &color, double &size)
virtual QgsStringMap properties() const =0
static QDomElement createVendorOptionElement(QDomDocument &doc, QString name, QString value)
static QColor decodeColor(QString str)
static bool convertPolygonSymbolizerToPointMarker(QDomElement &element, QgsSymbolLayerV2List &layerList)
static QDomElement createSvgParameterElement(QDomDocument &doc, QString name, QString value)
static QgsSymbolLayerV2Registry * instance()
return the single instance of this class (instantiate it if not exists)
static QVector< qreal > decodeSldRealVector(const QString &s)
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
double scaleFactor() const
static QString colorToName(const QColor &color)
Returns a friendly display name for a color.
static void createDisplacementElement(QDomDocument &doc, QDomElement &element, QPointF offset)
bool qgsVariantGreaterThan(const QVariant &lhs, const QVariant &rhs)
static void createOnlineResourceElement(QDomDocument &doc, QDomElement &element, QString path, QString format)
QgsSymbolLayerV2 * createSymbolLayerFromSld(QString name, QDomElement &element) const
create a new instance of symbol layer given symbol layer name and SLD
static bool needMarkerLine(QDomElement &element)
QMap< QString, QString > QgsStringMap
static bool needPointPatternFill(QDomElement &element)
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
double maxScale
The maximum scale, or 0.0 if unset.
bool qgsVariantLessThan(const QVariant &lhs, const QVariant &rhs)
static 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.
void setMapUnitScale(const QgsMapUnitScale &scale)
QgsMultiPolygon asMultiPolygon() const
return contents of the geometry as a multi polygon if wkbType is WKBMultiPolygon, otherwise an empty ...
virtual double estimateMaxBleed() const
Returns the estimated maximum distance which the layer style will bleed outside the drawn shape...
static QString encodeColor(QColor color)
QgsGeometry * offsetCurve(double distance, int segments, int joinStyle, double mitreLimit)
Returns an offset line at a given distance and side from an input line.
static Qt::BrushStyle decodeSldBrushStyle(QString str)
static bool displacementFromSldElement(QDomElement &element, QPointF &offset)
static WkbType flatType(WkbType type)
static QString encodePenStyle(Qt::PenStyle style)
static QDomElement saveSymbol(QString symbolName, QgsSymbolV2 *symbol, QDomDocument &doc)
static QDomElement expressionToOgcFilter(const QgsExpression &exp, QDomDocument &doc, QString *errorMessage=0)
Creates OGC filter XML element.
static bool createSymbolLayerV2ListFromSld(QDomElement &element, QGis::GeometryType geomType, QgsSymbolLayerV2List &layers)
static QString symbolPathToName(QString path)
Get symbols's name from its path.
static QgsSymbolLayerV2 * createMarkerLayerFromSld(QDomElement &element)
static QgsRenderContext createRenderContext(QPainter *p)
Creates a render context for a pixel based device.
static QPainter::CompositionMode decodeBlendMode(const QString &s)
static QIcon symbolPreviewIcon(QgsSymbolV2 *symbol, QSize size)
static QString encodeSldFontWeight(int weight)
static QString ogrFeatureStylePen(double width, double mmScaleFactor, double mapUnitsScaleFactor, const QColor &c, Qt::PenJoinStyle joinStyle=Qt::MiterJoin, Qt::PenCapStyle capStyle=Qt::FlatCap, double offset=0.0, const QVector< qreal > *dashPattern=0)
Create ogr feature style string for pen.
static QDomElement saveColorRamp(QString name, QgsVectorColorRampV2 *ramp, QDomDocument &doc)
static 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 bool fillFromSld(QDomElement &element, Qt::BrushStyle &brushStyle, QColor &color)
void setScaleFactor(double factor)
QgsGeometry * buffer(double distance, int segments)
Returns a buffer region around this geometry having the given width and with a specified number of se...
static QgsSymbolLayerV2 * createFillLayerFromSld(QDomElement &element)
static QString encodePoint(QPointF point)
static QMimeData * colorListToMimeData(const QgsNamedColorList colorList, const bool allFormats=true)
Creates mime data from a list of named colors.
static bool saveColorsToGpl(QFile &file, const QString paletteName, QgsNamedColorList colors)
Exports colors to a gpl GIMP palette file.
static QPointF offsetPoint(QPointF pt, double angle, double dist)
static QString encodeSldAlpha(int alpha)
static bool needLinePatternFill(QDomElement &element)
qreal alpha() const
Get alpha transparency 1 for opaque, 0 for invisible.
static Qt::PenCapStyle decodePenCapStyle(QString str)
static QgsNamedColorList importColorsFromGpl(QFile &file, bool &ok, QString &name)
Imports colors from a gpl GIMP palette file.
static Qt::PenStyle decodePenStyle(QString str)
void setRenderingPass(int renderingPass)
static bool createFunctionElement(QDomDocument &doc, QDomElement &element, QString function)
static QStringList listSvgFiles()
Return a list of all available svg files.
static QDomElement saveSymbols(QgsSymbolV2Map &symbols, QString tagName, QDomDocument &doc)
const Node * rootNode() const
Returns root node of the expression. Root node is null is parsing has failed.
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
static QString symbolNameToPath(QString name)
Get symbol's path from its name.
static bool externalMarkerFromSld(QDomElement &element, QString &path, QString &format, int &markIndex, QColor &color, double &size)
QVector< QgsPolygon > QgsMultiPolygon
a collection of QgsPolygons that share a common collection of attributes
static QFont::Style decodeSldFontStyle(QString str)
static QgsSymbolV2::OutputUnit decodeSldUom(QString str, double *scaleFactor)
int symbolLayerCount()
Returns total number of symbol layers contained in the symbol.
void setPainter(QPainter *p)
static bool needFontMarker(QDomElement &element)
double rasterScaleFactor() const
static void saveProperties(QgsStringMap props, QDomDocument &doc, QDomElement &element)
virtual QgsStringMap properties() const =0
QGis::WkbType wkbType() const
Returns type of wkb (point / linestring / polygon etc.)
static Qt::PenJoinStyle decodeSldLineJoinStyle(QString str)
QVector< QgsPolyline > QgsPolygon
polygon: first item of the list is outer ring, inner rings (if any) start from second item ...
static double estimateMaxSymbolBleed(QgsSymbolV2 *symbol)
Returns the maximum estimated bleed for the symbol.
static bool hasExternalGraphic(QDomElement &element)
static QStringList listSvgFilesAt(QString directory)
Return a list of svg files at the specified directory.
A class to represent a point.
virtual QColor color(double value) const =0
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
static bool needSvgMarker(QDomElement &element)
static bool needSvgFill(QDomElement &element)
QgsGeometry * pointOnSurface()
Returns a point within a geometry.
static bool geometryFromSldElement(QDomElement &element, QString &geomFunc)
static QgsSymbolLayerV2 * loadSymbolLayer(QDomElement &element)
static bool pointInPolygon(const QPolygonF &points, const QPointF &point)
Calculate whether a point is within of a QPolygonF.
static QgsSymbolLayerV2 * createLineLayerFromSld(QDomElement &element)
static QString encodeRealVector(const QVector< qreal > &v)
int renderingPass() const
virtual QString layerType() const =0
QVector< QgsPolyline > QgsMultiPolyline
a collection of QgsPolylines that share a common collection of attributes
virtual QgsSymbolV2 * subSymbol()
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
QgsPolyline asPolyline() const
return contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list ...
static void labelTextToSld(QDomDocument &doc, QDomElement &element, QString label, QFont font, QColor color=QColor(), double size=-1)
static void lineToSld(QDomDocument &doc, QDomElement &element, Qt::PenStyle penStyle, QColor color, double width=-1, const Qt::PenJoinStyle *penJoinStyle=0, const Qt::PenCapStyle *penCapStyle=0, const QVector< qreal > *customDashPattern=0, double dashOffset=0.0)
static void createGeometryElement(QDomDocument &doc, QDomElement &element, QString geomFunc)
Contains information about the context of a rendering operation.
static int decodeSldFontWeight(QString str)
static void createOpacityElement(QDomDocument &doc, QDomElement &element, QString alphaFunc)
static QString encodeBrushStyle(Qt::BrushStyle style)
static double lineWidthScaleFactor(const QgsRenderContext &c, QgsSymbolV2::OutputUnit u, const QgsMapUnitScale &scale=QgsMapUnitScale())
Returns the line width scale factor depending on the unit and the paint device.
static QPointF linesIntersection(QPointF p1, double t1, QPointF p2, double t2)
static QgsExpression * fieldOrExpressionToExpression(const QString &fieldOrExpression)
Return a new valid expression instance for given field or expression string.
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
QList< QgsSymbolLayerV2 * > QgsSymbolLayerV2List
static bool lineInfo(QPointF p1, QPointF p2, double &angle, double &t)
static QString encodeScaleMethod(QgsSymbolV2::ScaleMethod scaleMethod)
static QgsProject * instance()
access to canonical QgsProject instance
static QString _nameForSymbolType(QgsSymbolV2::SymbolType type)
static QString fieldOrExpressionFromExpression(QgsExpression *expression)
Return a field name if the whole expression is just a name of the field .
static QString encodeSldRealVector(const QVector< qreal > &v)
static QgsExpression * expressionFromOgcFilter(const QDomElement &element)
Parse XML with OGC filter into QGIS expression.
static QString encodeSldBrushStyle(Qt::BrushStyle style)
static void externalGraphicToSld(QDomDocument &doc, QDomElement &element, QString path, QString mime, QColor color, double size=-1)
static QgsVectorColorRampV2 * create(const QgsStringMap &properties=QgsStringMap())
static Q_DECL_DEPRECATED void wellKnownMarkerToSld(QDomDocument &doc, QDomElement &element, QString name, QColor color, QColor borderColor=QColor(), double borderWidth=-1, double size=-1)
static QgsGeometry * fromPolyline(const QgsPolyline &polyline)
construct geometry from a polyline
static Qt::PenJoinStyle decodePenJoinStyle(QString str)
static void clearSymbolMap(QgsSymbolV2Map &symbols)
static int decodeSldAlpha(QString str)
static bool rotationFromSldElement(QDomElement &element, QString &rotationFunc)
static QgsSymbolV2::ScaleMethod decodeScaleMethod(QString str)
static 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...
static QgsStringMap getSvgParameterList(QDomElement &element)
static QPointF polygonCentroid(const QPolygonF &points)
Calculate the centroid point of a QPolygonF.
void setRasterScaleFactor(double factor)
static QgsGeometry * fromPolygon(const QgsPolygon &polygon)
construct geometry from a polygon
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)
virtual void drawPreviewIcon(QgsSymbolV2RenderContext &context, QSize size)=0
static bool hasWellKnownMark(QDomElement &element)
static bool lineFromSld(QDomElement &element, Qt::PenStyle &penStyle, QColor &color, double &width, Qt::PenJoinStyle *penJoinStyle=0, Qt::PenCapStyle *penCapStyle=0, QVector< qreal > *customDashPattern=0, double *dashOffset=0)
static QPointF polygonPointOnSurface(const QPolygonF &points)
Calculate a point within of a QPolygonF.
static QPixmap symbolPreviewPixmap(QgsSymbolV2 *symbol, QSize size, QgsRenderContext *customContext=0)
void drawPreviewIcon(QPainter *painter, QSize size, QgsRenderContext *customContext=0)
Draw icon of the symbol that occupyies area given by size using the painter.
QgsPoint asPoint() const
return contents of the geometry as a point if wkbType is WKBPoint, otherwise returns [0...
static QPointF pointOnLineWithDistance(const QPointF &startPoint, const QPointF &directionPoint, double distance)
Returns a point on the line from startPoint to directionPoint that is a certain distance away from th...
double minScale
The minimum scale, or 0.0 if unset.
static bool opacityFromSldElement(QDomElement &element, QString &alphaFunc)
QString parserErrorString() const
Returns parser error.
virtual bool setSubSymbol(QgsSymbolV2 *symbol)
void setOutputUnit(QgsSymbolV2::OutputUnit u)
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
static void blurImageInPlace(QImage &image, const QRect &rect, int radius, bool alphaOnly)
Blurs an image in place, e.g.
static QgsSymbolV2::OutputUnit decodeOutputUnit(QString str)
static QString encodeSldLineCapStyle(Qt::PenCapStyle style)
static void externalMarkerToSld(QDomDocument &doc, QDomElement &element, QString path, QString format, int *markIndex=0, QColor color=QColor(), double size=-1)
static QColor parseColor(QString colorStr, bool strictEval=false)
Attempts to parse a string as a color using a variety of common formats, including hex codes...
static void premultiplyColor(QColor &rgb, int alpha)
Converts a QColor into a premultiplied ARGB QColor value using a specified alpha value.
static QgsNamedColorList colorListFromMimeData(const QMimeData *data)
Attempts to parse mime data as a list of named colors.
static bool needEllipseMarker(QDomElement &element)
static QString encodePenCapStyle(Qt::PenCapStyle style)