34 #include <QDomDocument>
36 #include <QDomElement>
43 return QString(
"%1,%2,%3,%4" ).arg( color.red() ).arg( color.green() ).arg( color.blue() ).arg( color.alpha() );
48 QStringList lst = str.split(
"," );
49 if ( lst.count() < 3 )
53 int red, green, blue, alpha;
55 green = lst[1].toInt();
56 blue = lst[2].toInt();
58 if ( lst.count() > 3 )
60 alpha = lst[3].toInt();
62 return QColor( red, green, blue, alpha );
67 return QString::number( alpha / 255.0,
'f', 2 );
73 double alpha = str.toDouble( &ok );
74 if ( !ok || alpha > 1 )
85 case QFont::StyleNormal:
return "normal";
86 case QFont::StyleItalic:
return "italic";
87 case QFont::StyleOblique:
return "oblique";
94 if ( str ==
"normal" )
return QFont::StyleNormal;
95 if ( str ==
"italic" )
return QFont::StyleItalic;
96 if ( str ==
"oblique" )
return QFont::StyleOblique;
97 return QFont::StyleNormal;
102 if ( weight == 50 )
return "normal";
103 if ( weight == 75 )
return "bold";
107 if ( weight < 0 )
return "100";
108 if ( weight > 99 )
return "900";
109 return QString::number( weight * 800 / 99 + 100 );
115 int weight = str.toInt( &ok );
116 if ( !ok )
return (
int ) QFont::Normal;
120 if ( weight > 900 )
return 99;
121 if ( weight < 100 )
return 0;
122 return ( weight - 100 ) * 99 / 800;
129 case Qt::NoPen:
return "no";
130 case Qt::SolidLine:
return "solid";
131 case Qt::DashLine:
return "dash";
132 case Qt::DotLine:
return "dot";
133 case Qt::DashDotLine:
return "dash dot";
134 case Qt::DashDotDotLine:
return "dash dot dot";
135 default:
return "???";
141 if ( str ==
"no" )
return Qt::NoPen;
142 if ( str ==
"solid" )
return Qt::SolidLine;
143 if ( str ==
"dash" )
return Qt::DashLine;
144 if ( str ==
"dot" )
return Qt::DotLine;
145 if ( str ==
"dash dot" )
return Qt::DashDotLine;
146 if ( str ==
"dash dot dot" )
return Qt::DashDotDotLine;
147 return Qt::SolidLine;
154 case Qt::BevelJoin:
return "bevel";
155 case Qt::MiterJoin:
return "miter";
156 case Qt::RoundJoin:
return "round";
157 default:
return "???";
163 if ( str ==
"bevel" )
return Qt::BevelJoin;
164 if ( str ==
"miter" )
return Qt::MiterJoin;
165 if ( str ==
"round" )
return Qt::RoundJoin;
166 return Qt::BevelJoin;
173 case Qt::BevelJoin:
return "bevel";
174 case Qt::MiterJoin:
return "mitre";
175 case Qt::RoundJoin:
return "round";
182 if ( str ==
"bevel" )
return Qt::BevelJoin;
183 if ( str ==
"mitre" )
return Qt::MiterJoin;
184 if ( str ==
"round" )
return Qt::RoundJoin;
185 return Qt::BevelJoin;
192 case Qt::SquareCap:
return "square";
193 case Qt::FlatCap:
return "flat";
194 case Qt::RoundCap:
return "round";
195 default:
return "???";
201 if ( str ==
"square" )
return Qt::SquareCap;
202 if ( str ==
"flat" )
return Qt::FlatCap;
203 if ( str ==
"round" )
return Qt::RoundCap;
204 return Qt::SquareCap;
211 case Qt::SquareCap:
return "square";
212 case Qt::FlatCap:
return "butt";
213 case Qt::RoundCap:
return "round";
220 if ( str ==
"square" )
return Qt::SquareCap;
221 if ( str ==
"butt" )
return Qt::FlatCap;
222 if ( str ==
"round" )
return Qt::RoundCap;
223 return Qt::SquareCap;
230 case Qt::SolidPattern :
return "solid";
231 case Qt::HorPattern :
return "horizontal";
232 case Qt::VerPattern :
return "vertical";
233 case Qt::CrossPattern :
return "cross";
234 case Qt::BDiagPattern :
return "b_diagonal";
235 case Qt::FDiagPattern :
return "f_diagonal";
236 case Qt::DiagCrossPattern :
return "diagonal_x";
237 case Qt::Dense1Pattern :
return "dense1";
238 case Qt::Dense2Pattern :
return "dense2";
239 case Qt::Dense3Pattern :
return "dense3";
240 case Qt::Dense4Pattern :
return "dense4";
241 case Qt::Dense5Pattern :
return "dense5";
242 case Qt::Dense6Pattern :
return "dense6";
243 case Qt::Dense7Pattern :
return "dense7";
244 case Qt::NoBrush :
return "no";
245 default:
return "???";
251 if ( str ==
"solid" )
return Qt::SolidPattern;
252 if ( str ==
"horizontal" )
return Qt::HorPattern;
253 if ( str ==
"vertical" )
return Qt::VerPattern;
254 if ( str ==
"cross" )
return Qt::CrossPattern;
255 if ( str ==
"b_diagonal" )
return Qt::BDiagPattern;
256 if ( str ==
"f_diagonal" )
return Qt::FDiagPattern;
257 if ( str ==
"diagonal_x" )
return Qt::DiagCrossPattern;
258 if ( str ==
"dense1" )
return Qt::Dense1Pattern;
259 if ( str ==
"dense2" )
return Qt::Dense2Pattern;
260 if ( str ==
"dense3" )
return Qt::Dense3Pattern;
261 if ( str ==
"dense4" )
return Qt::Dense4Pattern;
262 if ( str ==
"dense5" )
return Qt::Dense5Pattern;
263 if ( str ==
"dense6" )
return Qt::Dense6Pattern;
264 if ( str ==
"dense7" )
return Qt::Dense7Pattern;
265 if ( str ==
"no" )
return Qt::NoBrush;
266 return Qt::SolidPattern;
273 case Qt::CrossPattern:
return "cross";
274 case Qt::DiagCrossPattern:
return "x";
280 case Qt::HorPattern:
return "horline";
281 case Qt::VerPattern:
return "line";
282 case Qt::BDiagPattern:
return "slash";
283 case Qt::FDiagPattern:
return "backslash";
286 case Qt::Dense1Pattern:
287 case Qt::Dense2Pattern:
288 case Qt::Dense3Pattern:
289 case Qt::Dense4Pattern:
290 case Qt::Dense5Pattern:
291 case Qt::Dense6Pattern:
292 case Qt::Dense7Pattern:
302 if ( str ==
"horline" )
return Qt::HorPattern;
303 if ( str ==
"line" )
return Qt::VerPattern;
304 if ( str ==
"cross" )
return Qt::CrossPattern;
305 if ( str ==
"slash" )
return Qt::BDiagPattern;
306 if ( str ==
"backshash" )
return Qt::FDiagPattern;
307 if ( str ==
"x" )
return Qt::DiagCrossPattern;
309 if ( str.startsWith(
"brush://" ) )
317 return QString(
"%1,%2" ).arg( point.x() ).arg( point.y() );
322 QStringList lst = str.split(
',' );
323 if ( lst.count() != 2 )
324 return QPointF( 0, 0 );
325 return QPointF( lst[0].toDouble(), lst[1].toDouble() );
347 else if ( str ==
"MapUnit" )
362 *scaleFactor = 0.001;
363 return "http://www.opengeospatial.org/se/units/metre";
379 if ( str ==
"http://www.opengeospatial.org/se/units/metre" )
382 *scaleFactor = 1000.0;
385 else if ( str ==
"http://www.opengeospatial.org/se/units/foot" )
388 *scaleFactor = 304.8;
395 *scaleFactor = 1 / 0.00028;
401 QString vectorString;
402 QVector<qreal>::const_iterator it = v.constBegin();
403 for ( ; it != v.constEnd(); ++it )
405 if ( it != v.constBegin() )
407 vectorString.append(
";" );
409 vectorString.append( QString::number( *it ) );
416 QVector<qreal> resultVector;
418 QStringList realList = s.split(
";" );
419 QStringList::const_iterator it = realList.constBegin();
420 for ( ; it != realList.constEnd(); ++it )
422 resultVector.append( it->toDouble() );
430 QString vectorString;
431 QVector<qreal>::const_iterator it = v.constBegin();
432 for ( ; it != v.constEnd(); ++it )
434 if ( it != v.constBegin() )
436 vectorString.append(
" " );
438 vectorString.append( QString::number( *it ) );
445 QVector<qreal> resultVector;
447 QStringList realList = s.split(
" " );
448 QStringList::const_iterator it = realList.constBegin();
449 for ( ; it != realList.constEnd(); ++it )
451 resultVector.append( it->toDouble() );
459 QString encodedValue;
461 switch ( scaleMethod )
464 encodedValue =
"diameter";
467 encodedValue =
"area";
477 if ( str ==
"diameter" )
498 QPixmap pixmap( size );
499 pixmap.fill( Qt::transparent );
501 painter.begin( &pixmap );
502 painter.setRenderHint( QPainter::Antialiasing );
515 maxBleed = layerMaxBleed > maxBleed ? layerMaxBleed : maxBleed;
523 QPixmap pixmap( size );
524 pixmap.fill( Qt::transparent );
526 painter.begin( &pixmap );
527 painter.setRenderHint( QPainter::Antialiasing );
532 return QIcon( pixmap );
542 QPixmap pixmap( size );
543 pixmap.fill( Qt::transparent );
546 painter.begin( &pixmap );
553 for (
int i = 0; i < size.width(); i++ )
555 QPen pen( ramp->
color((
double ) i / size.width() ) );
556 painter.setPen( pen );
557 painter.drawLine( i, 0, i, size.height() - 1 );
566 uchar pixDataRGB[] = { 255, 255, 255, 255,
571 QImage img( pixDataRGB, 2, 2, 8, QImage::Format_ARGB32 );
573 int width = ( rect.width() < rect.height() ) ?
574 rect.width() / 2.5 : rect.height() / 2.5;
575 QPixmap pix = QPixmap::fromImage( img.scaled( width, width ) );
578 brush.setTexture( pix );
579 painter->fillRect( rect, brush );
591 double x1 = p1.x(), y1 = p1.y(), x2 = p2.x(), y2 = p2.y();
593 if ( x1 == x2 && y1 == y2 )
597 t = ( x1 == x2 ? DBL_MAX : ( y2 - y1 ) / ( x2 - x1 ) );
601 angle = ( y2 > y1 ?
M_PI / 2 :
M_PI * 3 / 2 );
603 angle = ( x2 > x1 ? 0 :
M_PI );
605 angle = ( y2 > y1 ? atan( t ) :
M_PI + atan( t ) );
607 angle = ( y2 > y1 ?
M_PI + atan( t ) : atan( t ) );
615 return QPointF( pt.x() + dist * cos( angle ), pt.y() + dist * sin( angle ) );
622 if (( t1 == DBL_MAX && t2 == DBL_MAX ) || qAbs( atan( t1 ) - atan( t2 ) ) < 0.175 )
626 if ( t1 == DBL_MAX || t2 == DBL_MAX )
632 QPointF pSwp = p1; p1 = p2; p2 = pSwp;
633 double tSwp = t1; t1 = t2; t2 = tSwp;
641 x = (( p1.y() - p2.y() ) + t2 * p2.x() - t1 * p1.x() ) / ( t2 - t1 );
644 y = p1.y() + t1 * ( x - p1.x() );
645 return QPointF( x, y );
653 if ( polyline.count() < 2 )
656 double angle = 0.0, t_new, t_old = 0;
657 QPointF pt_old, pt_new;
658 QPointF p1 = polyline[0], p2;
659 bool first_point =
true;
661 for (
int i = 1; i < polyline.count(); i++ )
665 if ( !
lineInfo( p1, p2, angle, t_new ) )
675 if ( !pt_tmp.isNull() )
679 newLine.append( pt_new );
689 newLine.append( pt_new );
699 QDomNode layerNode = element.firstChild();
701 while ( !layerNode.isNull() )
703 QDomElement e = layerNode.toElement();
706 if ( e.tagName() !=
"layer" )
717 QDomElement s = e.firstChildElement(
"symbol" );
724 QgsDebugMsg(
"symbol layer refused subsymbol: " + s.attribute(
"name" ) );
727 layers.append( layer );
731 layerNode = layerNode.nextSibling();
734 if ( layers.count() == 0 )
740 QString symbolType = element.attribute(
"type" );
743 if ( symbolType ==
"line" )
745 else if ( symbolType ==
"fill" )
747 else if ( symbolType ==
"marker" )
751 QgsDebugMsg(
"unknown symbol type " + symbolType );
755 if ( element.hasAttribute(
"outputUnit" ) )
759 symbol->
setAlpha( element.attribute(
"alpha",
"1.0" ).toDouble() );
766 QString layerClass = element.attribute(
"class" );
767 bool locked = element.attribute(
"locked" ).toInt();
768 int pass = element.attribute(
"pass" ).toInt();
802 QDomElement symEl = doc.createElement(
"symbol" );
804 symEl.setAttribute(
"name", name );
805 symEl.setAttribute(
"alpha", QString::number( symbol->
alpha() ) );
812 QDomElement layerEl = doc.createElement(
"layer" );
813 layerEl.setAttribute(
"class", layer->
layerType() );
814 layerEl.setAttribute(
"locked", layer->
isLocked() );
819 QString subname = QString(
"@%1@%2" ).arg( name ).arg( i );
821 layerEl.appendChild( subEl );
823 symEl.appendChild( layerEl );
836 if ( element.isNull() )
841 QString symbolizerName = element.localName();
843 if ( symbolizerName ==
"PointSymbolizer" )
846 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
847 if ( graphicElem.isNull() )
849 QgsDebugMsg(
"Graphic element not found in PointSymbolizer" );
885 if ( symbolizerName ==
"LineSymbolizer" )
888 QDomElement strokeElem = element.firstChildElement(
"Stroke" );
889 if ( strokeElem.isNull() )
891 QgsDebugMsg(
"Stroke element not found in LineSymbolizer" );
919 if ( symbolizerName ==
"PolygonSymbolizer" )
922 QDomElement fillElem = element.firstChildElement(
"Fill" );
923 QDomElement strokeElem = element.firstChildElement(
"Stroke" );
924 if ( fillElem.isNull() && strokeElem.isNull() )
926 QgsDebugMsg(
"neither Fill nor Stroke element not found in PolygonSymbolizer" );
980 QDomElement fillElem = element.firstChildElement(
"Fill" );
981 if ( fillElem.isNull() )
1003 QDomElement strokeElem = element.firstChildElement(
"Stroke" );
1004 if ( strokeElem.isNull() )
1022 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1023 if ( graphicElem.isNull() )
1045 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1046 if ( graphicElem.isNull() )
1049 QDomElement externalGraphicElem = graphicElem.firstChildElement(
"ExternalGraphic" );
1050 if ( externalGraphicElem.isNull() )
1054 QDomElement formatElem = externalGraphicElem.firstChildElement(
"Format" );
1055 if ( formatElem.isNull() )
1058 QString format = formatElem.firstChild().nodeValue();
1059 if ( format !=
"image/svg+xml" )
1061 QgsDebugMsg(
"unsupported External Graphic format found: " + format );
1066 QDomElement onlineResourceElem = externalGraphicElem.firstChildElement(
"OnlineResource" );
1067 QDomElement inlineContentElem = externalGraphicElem.firstChildElement(
"InlineContent" );
1068 if ( !onlineResourceElem.isNull() )
1073 else if ( !inlineContentElem.isNull() )
1086 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1087 if ( graphicElem.isNull() )
1090 QDomElement markElem = graphicElem.firstChildElement(
"Mark" );
1091 if ( markElem.isNull() )
1094 QDomElement wellKnownNameElem = markElem.firstChildElement(
"WellKnownName" );
1095 if ( wellKnownNameElem.isNull() )
1104 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1105 if ( graphicElem.isNull() )
1108 QDomElement markElem = graphicElem.firstChildElement(
"Mark" );
1109 if ( markElem.isNull() )
1113 QDomElement formatElem = markElem.firstChildElement(
"Format" );
1114 if ( formatElem.isNull() )
1117 QString format = formatElem.firstChild().nodeValue();
1118 if ( format !=
"ttf" )
1120 QgsDebugMsg(
"unsupported Graphic Mark format found: " + format );
1125 QDomElement onlineResourceElem = markElem.firstChildElement(
"OnlineResource" );
1126 QDomElement inlineContentElem = markElem.firstChildElement(
"InlineContent" );
1127 if ( !onlineResourceElem.isNull() )
1130 QDomElement markIndexElem = markElem.firstChildElement(
"MarkIndex" );
1131 if ( !markIndexElem.isNull() )
1134 else if ( !inlineContentElem.isNull() )
1149 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1150 if ( graphicElem.isNull() )
1154 for ( QgsStringMap::iterator it = vendorOptions.begin(); it != vendorOptions.end(); ++it )
1156 if ( it.key() ==
"widthHeightFactor" )
1167 QDomElement strokeElem = element.firstChildElement(
"Stroke" );
1168 if ( strokeElem.isNull() )
1171 QDomElement graphicStrokeElem = strokeElem.firstChildElement(
"GraphicStroke" );
1172 if ( graphicStrokeElem.isNull() )
1180 QDomElement fillElem = element.firstChildElement(
"Fill" );
1181 if ( fillElem.isNull() )
1184 QDomElement graphicFillElem = fillElem.firstChildElement(
"GraphicFill" );
1185 if ( graphicFillElem.isNull() )
1188 QDomElement graphicElem = graphicFillElem.firstChildElement(
"Graphic" );
1189 if ( graphicElem.isNull() )
1195 QColor fillColor, borderColor;
1196 double size, borderWidth;
1197 Qt::PenStyle borderStyle;
1198 if ( !
wellKnownMarkerFromSld( graphicElem, name, fillColor, borderColor, borderStyle, borderWidth, size ) )
1201 if ( name !=
"horline" )
1209 double angle = angleFunc.toDouble( &ok );
1210 if ( !ok || angle == 0 )
1218 Q_UNUSED( element );
1224 QDomElement fillElem = element.firstChildElement(
"Fill" );
1225 if ( fillElem.isNull() )
1228 QDomElement graphicFillElem = fillElem.firstChildElement(
"GraphicFill" );
1229 if ( graphicFillElem.isNull() )
1249 QDomElement fillElem = element.firstChildElement(
"Fill" );
1250 QDomElement strokeElem = element.firstChildElement(
"Stroke" );
1254 bool validFill =
false, validBorder =
false;
1259 Qt::BrushStyle fillStyle;
1261 if (
fillFromSld( fillElem, fillStyle, fillColor ) )
1267 Qt::PenStyle borderStyle;
1268 double borderWidth = 1.0, dashOffset = 0.0;
1269 QVector<qreal> customDashPattern;
1271 if (
lineFromSld( strokeElem, borderStyle, borderColor, borderWidth,
1272 0, 0, &customDashPattern, &dashOffset ) )
1275 if ( validFill || validBorder )
1278 map[
"name"] =
"square";
1279 map[
"color"] =
encodeColor( validFill ? fillColor : Qt::transparent );
1280 map[
"color_border"] =
encodeColor( validBorder ? borderColor : Qt::transparent );
1281 map[
"size"] = QString::number( 6 );
1282 map[
"angle"] = QString::number( 0 );
1290 bool validFill =
false, validBorder =
false;
1293 QString name, format;
1295 QColor fillColor, borderColor;
1296 double borderWidth = 1.0,
size = 0.0,
angle = 0.0;
1297 QPointF anchor, offset;
1300 QDomElement graphicFillElem = fillElem.firstChildElement(
"GraphicFill" );
1301 if ( !graphicFillElem.isNull() )
1304 QDomElement graphicElem = graphicFillElem.firstChildElement(
"Graphic" );
1305 if ( !graphicElem.isNull() )
1311 QDomElement graphicChildElem = graphicElem.firstChildElement();
1312 while ( !graphicChildElem.isNull() )
1314 if ( graphicChildElem.localName() ==
"Mark" )
1317 QDomElement wellKnownNameElem = graphicChildElem.firstChildElement(
"WellKnownName" );
1318 if ( !wellKnownNameElem.isNull() )
1320 name = wellKnownNameElem.firstChild().nodeValue();
1326 if ( graphicChildElem.localName() ==
"ExternalGraphic" || graphicChildElem.localName() ==
"Mark" )
1329 QDomElement formatElem = graphicChildElem.firstChildElement(
"Format" );
1330 if ( formatElem.isNull() )
1333 format = formatElem.firstChild().nodeValue();
1337 if ( graphicChildElem.localName() ==
"ExternalGraphic" && format !=
"image/svg+xml" )
1342 if ( graphicChildElem.localName() ==
"Mark" && format !=
"ttf" )
1346 QDomElement onlineResourceElem = graphicChildElem.firstChildElement(
"OnlineResource" );
1347 QDomElement inlineContentElem = graphicChildElem.firstChildElement(
"InlineContent" );
1349 if ( !onlineResourceElem.isNull() )
1351 name = onlineResourceElem.attributeNS(
"http://www.w3.org/1999/xlink",
"href" );
1353 if ( graphicChildElem.localName() ==
"Mark" && format ==
"ttf" )
1356 if ( name.startsWith(
"ttf://" ) )
1357 name = name.mid( 6 );
1360 QDomElement markIndexElem = graphicChildElem.firstChildElement(
"MarkIndex" );
1361 if ( markIndexElem.isNull() )
1365 int v = markIndexElem.firstChild().nodeValue().toInt( &ok );
1376 else if ( !inlineContentElem.isNull() )
1386 if ( graphicChildElem.localName() ==
"Mark" )
1395 if ( found && graphicChildElem.localName() ==
"Mark" )
1402 Qt::BrushStyle markFillStyle;
1404 QDomElement markFillElem = graphicChildElem.firstChildElement(
"Fill" );
1405 if (
fillFromSld( markFillElem, markFillStyle, fillColor ) )
1410 Qt::PenStyle borderStyle;
1411 double borderWidth = 1.0, dashOffset = 0.0;
1412 QVector<qreal> customDashPattern;
1414 QDomElement markStrokeElem = graphicChildElem.firstChildElement(
"Stroke" );
1415 if (
lineFromSld( markStrokeElem, borderStyle, borderColor, borderWidth,
1416 0, 0, &customDashPattern, &dashOffset ) )
1423 QDomElement opacityElem = graphicElem.firstChildElement(
"Opacity" );
1424 if ( !opacityElem.isNull() )
1425 fillColor.setAlpha(
decodeSldAlpha( opacityElem.firstChild().nodeValue() ) );
1427 QDomElement sizeElem = graphicElem.firstChildElement(
"Size" );
1428 if ( !sizeElem.isNull() )
1431 double v = sizeElem.firstChild().nodeValue().toDouble( &ok );
1440 double v = angleFunc.toDouble( &ok );
1450 if ( validFill || validBorder )
1452 if ( format ==
"image/svg+xml" )
1456 map[
"fill"] = fillColor.name();
1457 map[
"outline"] = borderColor.name();
1458 map[
"outline-width"] = QString::number( borderWidth );
1460 map[
"size"] = QString::number(
size );
1462 map[
"angle"] = QString::number(
angle );
1463 if ( !offset.isNull() )
1467 else if ( format ==
"ttf" )
1471 map[
"chr"] = markIndex;
1472 map[
"color"] =
encodeColor( validFill ? fillColor : Qt::transparent );
1474 map[
"size"] = QString::number(
size );
1476 map[
"angle"] = QString::number(
angle );
1477 if ( !offset.isNull() )
1484 if ( layers.isEmpty() )
1487 layerList << layers;
1494 QString patternName;
1495 switch ( brushStyle )
1500 case Qt::SolidPattern:
1501 if ( color.isValid() )
1504 if ( color.alpha() < 255 )
1509 case Qt::CrossPattern:
1510 case Qt::DiagCrossPattern:
1511 case Qt::HorPattern:
1512 case Qt::VerPattern:
1513 case Qt::BDiagPattern:
1514 case Qt::FDiagPattern:
1515 case Qt::Dense1Pattern:
1516 case Qt::Dense2Pattern:
1517 case Qt::Dense3Pattern:
1518 case Qt::Dense4Pattern:
1519 case Qt::Dense5Pattern:
1520 case Qt::Dense6Pattern:
1521 case Qt::Dense7Pattern:
1526 element.appendChild( doc.createComment( QString(
"Qt::BrushStyle '%1'' not supported yet" ).arg( brushStyle ) ) );
1530 QDomElement graphicFillElem = doc.createElement(
"se:GraphicFill" );
1531 element.appendChild( graphicFillElem );
1533 QDomElement graphicElem = doc.createElement(
"se:Graphic" );
1534 graphicFillElem.appendChild( graphicElem );
1536 QColor fillColor = patternName.startsWith(
"brush://" ) ? color : QColor();
1537 QColor borderColor = !patternName.startsWith(
"brush://" ) ? color : QColor();
1540 wellKnownMarkerToSld( doc, graphicElem, patternName, fillColor, borderColor, Qt::SolidLine, -1, -1 );
1547 brushStyle = Qt::SolidPattern;
1548 color = QColor(
"#808080" );
1550 if ( element.isNull() )
1552 brushStyle = Qt::NoBrush;
1557 QDomElement graphicFillElem = element.firstChildElement(
"GraphicFill" );
1559 if ( graphicFillElem.isNull() )
1562 for ( QgsStringMap::iterator it = svgParams.begin(); it != svgParams.end(); ++it )
1564 QgsDebugMsg( QString(
"found SvgParameter %1: %2" ).arg( it.key() ).arg( it.value() ) );
1566 if ( it.key() ==
"fill" )
1567 color = QColor( it.value() );
1568 else if ( it.key() ==
"fill-opacity" )
1574 QDomElement graphicElem = graphicFillElem.firstChildElement(
"Graphic" );
1575 if ( graphicElem.isNull() )
1578 QString patternName =
"square";
1579 QColor fillColor, borderColor;
1580 double borderWidth,
size;
1581 Qt::PenStyle borderStyle;
1582 if ( !
wellKnownMarkerFromSld( graphicElem, patternName, fillColor, borderColor, borderStyle, borderWidth, size ) )
1586 if ( brushStyle == Qt::NoBrush )
1589 QColor c = patternName.startsWith(
"brush://" ) ? fillColor : borderColor;
1598 Qt::PenStyle penStyle, QColor color,
double width,
1599 const Qt::PenJoinStyle *penJoinStyle,
const Qt::PenCapStyle *penCapStyle,
1600 const QVector<qreal> *customDashPattern,
double dashOffset )
1602 QVector<qreal> dashPattern;
1603 const QVector<qreal> *pattern = &dashPattern;
1605 if ( penStyle == Qt::CustomDashLine && !customDashPattern )
1607 element.appendChild( doc.createComment(
"WARNING: Custom dash pattern required but not provided. Using default dash pattern." ) );
1608 penStyle = Qt::DashLine;
1620 dashPattern.push_back( 4.0 );
1621 dashPattern.push_back( 2.0 );
1624 dashPattern.push_back( 1.0 );
1625 dashPattern.push_back( 2.0 );
1627 case Qt::DashDotLine:
1628 dashPattern.push_back( 4.0 );
1629 dashPattern.push_back( 2.0 );
1630 dashPattern.push_back( 1.0 );
1631 dashPattern.push_back( 2.0 );
1633 case Qt::DashDotDotLine:
1634 dashPattern.push_back( 4.0 );
1635 dashPattern.push_back( 2.0 );
1636 dashPattern.push_back( 1.0 );
1637 dashPattern.push_back( 2.0 );
1638 dashPattern.push_back( 1.0 );
1639 dashPattern.push_back( 2.0 );
1642 case Qt::CustomDashLine:
1643 Q_ASSERT( customDashPattern );
1644 pattern = customDashPattern;
1648 element.appendChild( doc.createComment( QString(
"Qt::BrushStyle '%1'' not supported yet" ).arg( penStyle ) ) );
1652 if ( color.isValid() )
1655 if ( color.alpha() < 255 )
1665 if ( pattern->size() > 0 )
1675 Qt::PenStyle &penStyle, QColor &color,
double &width,
1676 Qt::PenJoinStyle *penJoinStyle, Qt::PenCapStyle *penCapStyle,
1677 QVector<qreal> *customDashPattern,
double *dashOffset )
1681 penStyle = Qt::SolidLine;
1682 color = QColor(
"#000000" );
1685 *penJoinStyle = Qt::BevelJoin;
1687 *penCapStyle = Qt::SquareCap;
1688 if ( customDashPattern )
1689 customDashPattern->clear();
1693 if ( element.isNull() )
1695 penStyle = Qt::NoPen;
1701 for ( QgsStringMap::iterator it = svgParams.begin(); it != svgParams.end(); ++it )
1703 QgsDebugMsg( QString(
"found SvgParameter %1: %2" ).arg( it.key() ).arg( it.value() ) );
1705 if ( it.key() ==
"stroke" )
1707 color = QColor( it.value() );
1709 else if ( it.key() ==
"stroke-opacity" )
1713 else if ( it.key() ==
"stroke-width" )
1716 double w = it.value().toDouble( &ok );
1720 else if ( it.key() ==
"stroke-linejoin" && penJoinStyle )
1724 else if ( it.key() ==
"stroke-linecap" && penCapStyle )
1728 else if ( it.key() ==
"stroke-dasharray" )
1731 if ( dashPattern.size() > 0 )
1735 bool dashPatternFound =
false;
1737 if ( dashPattern.count() == 2 )
1739 if ( dashPattern.at( 0 ) == 4.0 &&
1740 dashPattern.at( 1 ) == 2.0 )
1742 penStyle = Qt::DashLine;
1743 dashPatternFound =
true;
1745 else if ( dashPattern.at( 0 ) == 1.0 &&
1746 dashPattern.at( 1 ) == 2.0 )
1748 penStyle = Qt::DotLine;
1749 dashPatternFound =
true;
1752 else if ( dashPattern.count() == 4 )
1754 if ( dashPattern.at( 0 ) == 4.0 &&
1755 dashPattern.at( 1 ) == 2.0 &&
1756 dashPattern.at( 2 ) == 1.0 &&
1757 dashPattern.at( 3 ) == 2.0 )
1759 penStyle = Qt::DashDotLine;
1760 dashPatternFound =
true;
1763 else if ( dashPattern.count() == 6 )
1765 if ( dashPattern.at( 0 ) == 4.0 &&
1766 dashPattern.at( 1 ) == 2.0 &&
1767 dashPattern.at( 2 ) == 1.0 &&
1768 dashPattern.at( 3 ) == 2.0 &&
1769 dashPattern.at( 4 ) == 1.0 &&
1770 dashPattern.at( 5 ) == 2.0 )
1772 penStyle = Qt::DashDotDotLine;
1773 dashPatternFound =
true;
1778 if ( !dashPatternFound )
1780 if ( customDashPattern )
1782 penStyle = Qt::CustomDashLine;
1783 *customDashPattern = dashPattern;
1787 QgsDebugMsg(
"custom dash pattern required but not provided. Using default dash pattern." );
1788 penStyle = Qt::DashLine;
1793 else if ( it.key() ==
"stroke-dashoffset" && dashOffset )
1796 double d = it.value().toDouble( &ok );
1806 QString path, QString mime,
1807 QColor color,
double size )
1809 QDomElement externalGraphicElem = doc.createElement(
"se:ExternalGraphic" );
1810 element.appendChild( externalGraphicElem );
1819 QDomElement sizeElem = doc.createElement(
"se:Size" );
1820 sizeElem.appendChild( doc.createTextNode( QString::number( size ) ) );
1821 element.appendChild( sizeElem );
1826 QString &path, QString &mime,
1827 QColor &color,
double &
size )
1832 QDomElement externalGraphicElem = element.firstChildElement(
"ExternalGraphic" );
1833 if ( externalGraphicElem.isNull() )
1838 QDomElement sizeElem = element.firstChildElement(
"Size" );
1839 if ( !sizeElem.isNull() )
1842 double s = sizeElem.firstChild().nodeValue().toDouble( &ok );
1851 QString path, QString format,
int *markIndex,
1852 QColor color,
double size )
1854 QDomElement markElem = doc.createElement(
"se:Mark" );
1855 element.appendChild( markElem );
1861 QDomElement markIndexElem = doc.createElement(
"se:MarkIndex" );
1862 markIndexElem.appendChild( doc.createTextNode( QString::number( *markIndex ) ) );
1863 markElem.appendChild( markIndexElem );
1867 QDomElement fillElem = doc.createElement(
"se:Fill" );
1868 fillToSld( doc, fillElem, Qt::SolidPattern, color );
1869 markElem.appendChild( fillElem );
1874 QDomElement sizeElem = doc.createElement(
"se:Size" );
1875 sizeElem.appendChild( doc.createTextNode( QString::number( size ) ) );
1876 element.appendChild( sizeElem );
1881 QString &path, QString &format,
int &markIndex,
1882 QColor &color,
double &
size )
1890 QDomElement markElem = element.firstChildElement(
"Mark" );
1891 if ( markElem.isNull() )
1896 QDomElement markIndexElem = markElem.firstChildElement(
"MarkIndex" );
1897 if ( !markIndexElem.isNull() )
1900 int i = markIndexElem.firstChild().nodeValue().toInt( &ok );
1906 QDomElement fillElem = markElem.firstChildElement(
"Fill" );
1907 Qt::BrushStyle b = Qt::SolidPattern;
1912 QDomElement sizeElem = element.firstChildElement(
"Size" );
1913 if ( !sizeElem.isNull() )
1916 double s = sizeElem.firstChild().nodeValue().toDouble( &ok );
1925 QString name, QColor color, QColor borderColor,
1926 double borderWidth,
double size )
1928 wellKnownMarkerToSld( doc, element, name, color, borderColor, Qt::SolidLine, borderWidth, size );
1932 QString name, QColor color, QColor borderColor, Qt::PenStyle borderStyle,
1933 double borderWidth,
double size )
1935 QDomElement markElem = doc.createElement(
"se:Mark" );
1936 element.appendChild( markElem );
1938 QDomElement wellKnownNameElem = doc.createElement(
"se:WellKnownName" );
1939 wellKnownNameElem.appendChild( doc.createTextNode( name ) );
1940 markElem.appendChild( wellKnownNameElem );
1943 if ( color.isValid() )
1945 QDomElement fillElem = doc.createElement(
"se:Fill" );
1946 fillToSld( doc, fillElem, Qt::SolidPattern, color );
1947 markElem.appendChild( fillElem );
1951 if ( borderColor.isValid() )
1953 QDomElement strokeElem = doc.createElement(
"se:Stroke" );
1954 lineToSld( doc, strokeElem, borderStyle, borderColor, borderWidth );
1955 markElem.appendChild( strokeElem );
1961 QDomElement sizeElem = doc.createElement(
"se:Size" );
1962 sizeElem.appendChild( doc.createTextNode( QString::number( size ) ) );
1963 element.appendChild( sizeElem );
1968 QString &name, QColor &color, QColor &borderColor,
1969 double &borderWidth,
double &
size )
1971 Qt::PenStyle borderStyle;
1976 QString &name, QColor &color, QColor &borderColor, Qt::PenStyle &borderStyle,
1977 double &borderWidth,
double &
size )
1983 borderColor = QColor(
"#000000" );
1987 QDomElement markElem = element.firstChildElement(
"Mark" );
1988 if ( markElem.isNull() )
1991 QDomElement wellKnownNameElem = markElem.firstChildElement(
"WellKnownName" );
1992 if ( !wellKnownNameElem.isNull() )
1994 name = wellKnownNameElem.firstChild().nodeValue();
1995 QgsDebugMsg(
"found Mark with well known name: " + name );
1999 QDomElement fillElem = markElem.firstChildElement(
"Fill" );
2000 Qt::BrushStyle b = Qt::SolidPattern;
2005 QDomElement strokeElem = markElem.firstChildElement(
"Stroke" );
2006 lineFromSld( strokeElem, borderStyle, borderColor, borderWidth );
2010 QDomElement sizeElem = element.firstChildElement(
"Size" );
2011 if ( !sizeElem.isNull() )
2014 double s = sizeElem.firstChild().nodeValue().toDouble( &ok );
2024 if ( !rotationFunc.isEmpty() )
2026 QDomElement rotationElem = doc.createElement(
"se:Rotation" );
2028 element.appendChild( rotationElem );
2034 QDomElement rotationElem = element.firstChildElement(
"Rotation" );
2035 if ( !rotationElem.isNull() )
2045 if ( !alphaFunc.isEmpty() )
2047 QDomElement opacityElem = doc.createElement(
"se:Opacity" );
2049 element.appendChild( opacityElem );
2055 QDomElement opacityElem = element.firstChildElement(
"Opacity" );
2056 if ( !opacityElem.isNull() )
2065 if ( offset.isNull() )
2068 QDomElement displacementElem = doc.createElement(
"se:Displacement" );
2069 element.appendChild( displacementElem );
2071 QDomElement dispXElem = doc.createElement(
"se:DisplacementX" );
2072 dispXElem.appendChild( doc.createTextNode( QString::number( offset.x() ) ) );
2074 QDomElement dispYElem = doc.createElement(
"se:DisplacementY" );
2075 dispYElem.appendChild( doc.createTextNode( QString::number( offset.y() ) ) );
2077 displacementElem.appendChild( dispXElem );
2078 displacementElem.appendChild( dispYElem );
2083 offset = QPointF( 0, 0 );
2085 QDomElement displacementElem = element.firstChildElement(
"Displacement" );
2086 if ( displacementElem.isNull() )
2089 QDomElement dispXElem = displacementElem.firstChildElement(
"DisplacementX" );
2090 if ( !dispXElem.isNull() )
2093 double offsetX = dispXElem.firstChild().nodeValue().toDouble( &ok );
2095 offset.setX( offsetX );
2098 QDomElement dispYElem = displacementElem.firstChildElement(
"DisplacementY" );
2099 if ( !dispYElem.isNull() )
2102 double offsetY = dispYElem.firstChild().nodeValue().toDouble( &ok );
2104 offset.setY( offsetY );
2111 QString label, QFont font,
2112 QColor color,
double size )
2114 QDomElement labelElem = doc.createElement(
"se:Label" );
2115 labelElem.appendChild( doc.createTextNode( label ) );
2116 element.appendChild( labelElem );
2118 QDomElement fontElem = doc.createElement(
"se:Font" );
2119 element.appendChild( fontElem );
2123 fontElem.appendChild( createSldParameterElement( doc,
"font-style",
encodeSldFontStyle( font.style() ) ) );
2124 fontElem.appendChild( createSldParameterElement( doc,
"font-weight",
encodeSldFontWeight( font.weight() ) ) );
2129 if ( color.isValid() )
2131 QDomElement fillElem = doc.createElement(
"Fill" );
2132 fillToSld( doc, fillElem, Qt::SolidPattern, color );
2133 element.appendChild( fillElem );
2138 Qt::PenJoinStyle joinStyle,
2139 Qt::PenCapStyle capStyle,
2141 const QVector<qreal>* dashPattern )
2144 penStyle.append(
"PEN(" );
2145 penStyle.append(
"c:" );
2146 penStyle.append( c.name() );
2147 penStyle.append(
",w:" );
2149 penStyle.append( QString::number( width * mmScaleFactor ) );
2150 penStyle.append(
"mm" );
2153 if ( dashPattern && dashPattern->size() > 0 )
2155 penStyle.append(
",p:\"" );
2156 QVector<qreal>::const_iterator pIt = dashPattern->constBegin();
2157 for ( ; pIt != dashPattern->constEnd(); ++pIt )
2159 if ( pIt != dashPattern->constBegin() )
2161 penStyle.append(
" " );
2163 penStyle.append( QString::number( *pIt * mapUnitScaleFactor ) );
2164 penStyle.append(
"g" );
2166 penStyle.append(
"\"" );
2170 penStyle.append(
",cap:" );
2174 penStyle.append(
"p" );
2177 penStyle.append(
"r" );
2181 penStyle.append(
"b" );
2185 penStyle.append(
",j:" );
2186 switch ( joinStyle )
2189 penStyle.append(
"b" );
2192 penStyle.append(
"r" );
2196 penStyle.append(
"m" );
2202 penStyle.append(
",dp:" );
2203 penStyle.append( QString::number( offset * mapUnitScaleFactor ) );
2204 penStyle.append(
"g" );
2207 penStyle.append(
")" );
2214 brushStyle.append(
"BRUSH(" );
2215 brushStyle.append(
"fc:" );
2216 brushStyle.append( fillColor.name() );
2217 brushStyle.append(
")" );
2223 if ( geomFunc.isEmpty() )
2226 QDomElement geometryElem = doc.createElement(
"Geometry" );
2227 element.appendChild( geometryElem );
2257 QDomElement geometryElem = element.firstChildElement(
"Geometry" );
2258 if ( geometryElem.isNull() )
2270 element.appendChild( doc.createComment(
"Parser Error: " + expr.
parserErrorString() +
" - Expression was: " + function ) );
2274 if ( !filterElem.isNull() )
2275 element.appendChild( filterElem );
2302 QString path, QString format )
2306 QDomElement onlineResourceElem = doc.createElement(
"se:OnlineResource" );
2307 onlineResourceElem.setAttribute(
"xlink:type",
"simple" );
2308 onlineResourceElem.setAttribute(
"xlink:href", url );
2309 element.appendChild( onlineResourceElem );
2311 QDomElement formatElem = doc.createElement(
"se:Format" );
2312 formatElem.appendChild( doc.createTextNode( format ) );
2313 element.appendChild( formatElem );
2320 QDomElement onlineResourceElem = element.firstChildElement(
"OnlineResource" );
2321 if ( onlineResourceElem.isNull() )
2324 path = onlineResourceElem.attributeNS(
"http://www.w3.org/1999/xlink",
"href" );
2326 QDomElement formatElem = element.firstChildElement(
"Format" );
2327 if ( formatElem.isNull() )
2330 format = formatElem.firstChild().nodeValue();
2337 QDomElement nodeElem = doc.createElement(
"se:SvgParameter" );
2338 nodeElem.setAttribute(
"name", name );
2339 nodeElem.appendChild( doc.createTextNode( value ) );
2347 QDomElement paramElem = element.firstChildElement();
2348 while ( !paramElem.isNull() )
2350 if ( paramElem.localName() ==
"SvgParameter" || paramElem.localName() ==
"CssParameter" )
2352 QString name = paramElem.attribute(
"name" );
2353 QString value = paramElem.firstChild().nodeValue();
2355 if ( !name.isEmpty() && !value.isEmpty() )
2356 params[ name ] = value;
2359 paramElem = paramElem.nextSiblingElement();
2367 QDomElement nodeElem = doc.createElement(
"VendorOption" );
2368 nodeElem.setAttribute(
"name", name );
2369 nodeElem.appendChild( doc.createTextNode( value ) );
2377 QDomElement paramElem = element.firstChildElement(
"VendorOption" );
2378 while ( !paramElem.isNull() )
2380 QString name = paramElem.attribute(
"name" );
2381 QString value = paramElem.firstChild().nodeValue();
2383 if ( !name.isEmpty() && !value.isEmpty() )
2384 params[ name ] = value;
2386 paramElem = paramElem.nextSiblingElement(
"VendorOption" );
2396 QDomElement e = element.firstChildElement();
2397 while ( !e.isNull() )
2399 if ( e.tagName() !=
"prop" )
2405 QString propKey = e.attribute(
"k" );
2406 QString propValue = e.attribute(
"v" );
2407 props[propKey] = propValue;
2409 e = e.nextSiblingElement();
2417 for ( QgsStringMap::iterator it = props.begin(); it != props.end(); ++it )
2419 QDomElement propEl = doc.createElement(
"prop" );
2420 propEl.setAttribute(
"k", it.key() );
2421 propEl.setAttribute(
"v", it.value() );
2422 element.appendChild( propEl );
2431 QDomElement e = element.firstChildElement();
2433 while ( !e.isNull() )
2435 if ( e.tagName() ==
"symbol" )
2438 if ( symbol != NULL )
2439 symbols.insert( e.attribute(
"name" ), symbol );
2445 e = e.nextSiblingElement();
2452 QStringList subsymbols;
2454 for ( QMap<QString, QgsSymbolV2*>::iterator it = symbols.begin(); it != symbols.end(); ++it )
2456 if ( it.key()[0] !=
'@' )
2460 subsymbols.append( it.key() );
2462 QStringList parts = it.key().split(
"@" );
2463 if ( parts.count() < 3 )
2465 QgsDebugMsg(
"found subsymbol with invalid name: " + it.key() );
2469 QString symname = parts[1];
2470 int symlayer = parts[2].toInt();
2472 if ( !symbols.contains( symname ) )
2474 QgsDebugMsg(
"subsymbol references invalid symbol: " + symname );
2482 QgsDebugMsg(
"subsymbol references invalid symbol layer: " + QString::number( symlayer ) );
2491 QgsDebugMsg(
"symbol layer refused subsymbol: " + it.key() );
2498 for (
int i = 0; i < subsymbols.count(); i++ )
2499 symbols.take( subsymbols[i] );
2506 QDomElement symbolsElem = doc.createElement( tagName );
2509 for ( QMap<QString, QgsSymbolV2*>::iterator its = symbols.begin(); its != symbols.end(); ++its )
2511 QDomElement symEl =
saveSymbol( its.key(), its.value(), doc );
2512 symbolsElem.appendChild( symEl );
2520 foreach ( QString name, symbols.keys() )
2522 delete symbols.value( name );
2530 QString rampType = element.attribute(
"type" );
2535 if ( rampType ==
"gradient" )
2537 else if ( rampType ==
"random" )
2539 else if ( rampType ==
"colorbrewer" )
2541 else if ( rampType ==
"cpt-city" )
2545 QgsDebugMsg(
"unknown colorramp type " + rampType );
2553 QDomElement rampEl = doc.createElement(
"colorramp" );
2554 rampEl.setAttribute(
"type", ramp->
type() );
2555 rampEl.setAttribute(
"name", name );
2565 if ( colorStr.startsWith(
"rgb(" ) )
2567 colorStr = colorStr.mid( 4, colorStr.size() - 5 ).trimmed();
2569 QStringList p = colorStr.split( QChar(
',' ) );
2570 if ( p.count() != 3 )
2572 return QColor( p[0].toInt(), p[1].toInt(), p[2].toInt() );
2621 if ( p && p->device() )
2640 QImage::Format format = image->format();
2641 if ( format != QImage::Format_ARGB32_Premultiplied && format != QImage::Format_ARGB32 )
2648 for (
int heightIndex = 0; heightIndex < image->height(); ++heightIndex )
2650 QRgb* scanLine = ( QRgb* )image->scanLine( heightIndex );
2651 for (
int widthIndex = 0; widthIndex < image->width(); ++widthIndex )
2653 myRgb = scanLine[widthIndex];
2654 if ( format == QImage::Format_ARGB32_Premultiplied )
2655 scanLine[widthIndex] = qRgba( alpha * qRed( myRgb ), alpha * qGreen( myRgb ), alpha * qBlue( myRgb ), alpha * qAlpha( myRgb ) );
2657 scanLine[widthIndex] = qRgba( qRed( myRgb ), qGreen( myRgb ), qBlue( myRgb ), alpha * qAlpha( myRgb ) );
2665 int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 };
2666 int alpha = ( radius < 1 ) ? 16 : ( radius > 17 ) ? 1 : tab[radius-1];
2668 if ( image.format() != QImage::Format_ARGB32_Premultiplied
2669 && image.format() != QImage::Format_RGB32 )
2671 image = image.convertToFormat( QImage::Format_ARGB32_Premultiplied );
2674 int r1 = rect.top();
2675 int r2 = rect.bottom();
2676 int c1 = rect.left();
2677 int c2 = rect.right();
2679 int bpl = image.bytesPerLine();
2687 i1 = i2 = ( QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3 );
2689 for (
int col = c1; col <= c2; col++ )
2691 p = image.scanLine( r1 ) + col * 4;
2692 for (
int i = i1; i <= i2; i++ )
2693 rgba[i] = p[i] << 4;
2696 for (
int j = r1; j < r2; j++, p += bpl )
2697 for (
int i = i1; i <= i2; i++ )
2698 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
2701 for (
int row = r1; row <= r2; row++ )
2703 p = image.scanLine( row ) + c1 * 4;
2704 for (
int i = i1; i <= i2; i++ )
2705 rgba[i] = p[i] << 4;
2708 for (
int j = c1; j < c2; j++, p += 4 )
2709 for (
int i = i1; i <= i2; i++ )
2710 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
2713 for (
int col = c1; col <= c2; col++ )
2715 p = image.scanLine( r2 ) + col * 4;
2716 for (
int i = i1; i <= i2; i++ )
2717 rgba[i] = p[i] << 4;
2720 for (
int j = r1; j < r2; j++, p -= bpl )
2721 for (
int i = i1; i <= i2; i++ )
2722 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
2725 for (
int row = r1; row <= r2; row++ )
2727 p = image.scanLine( row ) + c2 * 4;
2728 for (
int i = i1; i <= i2; i++ )
2729 rgba[i] = p[i] << 4;
2732 for (
int j = c1; j < c2; j++, p -= 4 )
2733 for (
int i = i1; i <= i2; i++ )
2734 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
2739 static bool _QVariantLessThan(
const QVariant& lhs,
const QVariant& rhs )
2741 switch ( lhs.type() )
2744 return lhs.toInt() < rhs.toInt();
2745 case QVariant::UInt:
2746 return lhs.toUInt() < rhs.toUInt();
2747 case QVariant::LongLong:
2748 return lhs.toLongLong() < rhs.toLongLong();
2749 case QVariant::ULongLong:
2750 return lhs.toULongLong() < rhs.toULongLong();
2751 case QVariant::Double:
2752 return lhs.toDouble() < rhs.toDouble();
2753 case QVariant::Char:
2754 return lhs.toChar() < rhs.toChar();
2755 case QVariant::Date:
2756 return lhs.toDate() < rhs.toDate();
2757 case QVariant::Time:
2758 return lhs.toTime() < rhs.toTime();
2759 case QVariant::DateTime:
2760 return lhs.toDateTime() < rhs.toDateTime();
2762 return QString::localeAwareCompare( lhs.toString(), rhs.toString() ) < 0;
2766 static bool _QVariantGreaterThan(
const QVariant& lhs,
const QVariant& rhs )
2768 return ! _QVariantLessThan( lhs, rhs );
2774 if ( order == Qt::AscendingOrder )
2788 double dx = directionPoint.x() - startPoint.x();
2789 double dy = directionPoint.y() - startPoint.y();
2790 double length = sqrt( dx * dx + dy * dy );
2791 double scaleFactor = distance / length;
2792 return QPointF( startPoint.x() + dx * scaleFactor, startPoint.y() + dy * scaleFactor );
2802 for (
int i = 0; i < svgPaths.size(); i++ )
2804 QDir dir( svgPaths[i] );
2805 foreach ( QString item, dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
2807 svgPaths.insert( i + 1, dir.path() +
"/" + item );
2810 foreach ( QString item, dir.entryList( QStringList(
"*.svg" ), QDir::Files ) )
2813 list.append( dir.path() +
"/" + item );
2825 QStringList svgPaths;
2826 svgPaths.append( directory );
2828 for (
int i = 0; i < svgPaths.size(); i++ )
2830 QDir dir( svgPaths[i] );
2831 foreach ( QString item, dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
2833 svgPaths.insert( i + 1, dir.path() +
"/" + item );
2836 foreach ( QString item, dir.entryList( QStringList(
"*.svg" ), QDir::Files ) )
2838 list.append( dir.path() +
"/" + item );
2850 if ( QFile( name ).exists() )
2851 return QFileInfo( name ).canonicalFilePath();
2854 if ( name.contains(
"://" ) )
2857 if ( url.isValid() && !url.scheme().isEmpty() )
2859 if ( url.scheme().compare(
"file", Qt::CaseInsensitive ) == 0 )
2862 name = url.toLocalFile();
2863 if ( QFile( name ).exists() )
2865 return QFileInfo( name ).canonicalFilePath();
2879 for (
int i = 0; i < svgPaths.size(); i++ )
2881 QString svgPath = svgPaths[i];
2882 if ( svgPath.endsWith( QString(
"/" ) ) )
2888 QFileInfo myInfo( name );
2889 QString myFileName = myInfo.fileName();
2890 QString myLowestDir = myInfo.dir().dirName();
2891 QString myLocalPath = svgPath + QString( myLowestDir.isEmpty() ?
"" :
"/" + myLowestDir ) +
"/" + myFileName;
2893 QgsDebugMsg(
"Alternative svg path: " + myLocalPath );
2894 if ( QFile( myLocalPath ).exists() )
2897 return QFileInfo( myLocalPath ).canonicalFilePath();
2899 else if ( myInfo.isRelative() )
2902 QString alternatePath = pfi.canonicalPath() + QDir::separator() + name;
2903 if ( pfi.exists() && QFile( alternatePath ).exists() )
2906 return QFileInfo( alternatePath ).canonicalFilePath();
2916 QgsDebugMsg(
"Computed alternate path but no svg there either" );
2926 QFileInfo fi( path );
2930 path = fi.canonicalFilePath();
2934 bool isInSvgPathes =
false;
2935 for (
int i = 0; i < svgPaths.size(); i++ )
2937 QString dir = QFileInfo( svgPaths[i] ).canonicalFilePath();
2939 if ( !dir.isEmpty() && path.startsWith( dir ) )
2941 path = path.mid( dir.size() + 1 );
2942 isInSvgPathes =
true;
2947 if ( isInSvgPathes )
2956 double cx = 0, cy = 0;
2957 double area, sum = 0;
2958 for (
int i = points.count() - 1, j = 0; j < points.count(); i = j++ )
2960 const QPointF& p1 = points[i];
2961 const QPointF& p2 = points[j];
2962 area = p1.x() * p2.y() - p1.y() * p2.x();
2964 cx += ( p1.x() + p2.x() ) * area;
2965 cy += ( p1.y() + p2.y() ) * area;
2971 return QPointF( cx, cy );
2977 if ( fieldOrExpression.isEmpty() )
2996 return static_cast<const QgsExpression::NodeColumnRef*>( n )->name();