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 );
511 QPixmap pixmap( size );
512 pixmap.fill( Qt::transparent );
514 painter.begin( &pixmap );
515 painter.setRenderHint( QPainter::Antialiasing );
520 return QIcon( pixmap );
530 QPixmap pixmap( size );
531 pixmap.fill( Qt::transparent );
534 painter.begin( &pixmap );
541 for (
int i = 0; i < size.width(); i++ )
543 QPen pen( ramp->
color((
double ) i / size.width() ) );
544 painter.setPen( pen );
545 painter.drawLine( i, 0, i, size.height() - 1 );
554 uchar pixDataRGB[] = { 255, 255, 255, 255,
559 QImage img( pixDataRGB, 2, 2, 8, QImage::Format_ARGB32 );
561 int width = ( rect.width() < rect.height() ) ?
562 rect.width() / 2.5 : rect.height() / 2.5;
563 QPixmap pix = QPixmap::fromImage( img.scaled( width, width ) );
566 brush.setTexture( pix );
567 painter->fillRect( rect, brush );
579 double x1 = p1.x(), y1 = p1.y(), x2 = p2.x(), y2 = p2.y();
581 if ( x1 == x2 && y1 == y2 )
585 t = ( x1 == x2 ? DBL_MAX : ( y2 - y1 ) / ( x2 - x1 ) );
589 angle = ( y2 > y1 ?
M_PI / 2 :
M_PI * 3 / 2 );
591 angle = ( x2 > x1 ? 0 :
M_PI );
593 angle = ( y2 > y1 ? atan( t ) :
M_PI + atan( t ) );
595 angle = ( y2 > y1 ?
M_PI + atan( t ) : atan( t ) );
603 return QPointF( pt.x() + dist * cos( angle ), pt.y() + dist * sin( angle ) );
610 if (( t1 == DBL_MAX && t2 == DBL_MAX ) || qAbs( atan( t1 ) - atan( t2 ) ) < 0.175 )
614 if ( t1 == DBL_MAX || t2 == DBL_MAX )
620 QPointF pSwp = p1; p1 = p2; p2 = pSwp;
621 double tSwp = t1; t1 = t2; t2 = tSwp;
629 x = (( p1.y() - p2.y() ) + t2 * p2.x() - t1 * p1.x() ) / ( t2 - t1 );
632 y = p1.y() + t1 * ( x - p1.x() );
633 return QPointF( x, y );
641 if ( polyline.count() < 2 )
644 double angle = 0.0, t_new, t_old = 0;
645 QPointF pt_old, pt_new;
646 QPointF p1 = polyline[0], p2;
647 bool first_point =
true;
649 for (
int i = 1; i < polyline.count(); i++ )
653 if ( !
lineInfo( p1, p2, angle, t_new ) )
663 if ( !pt_tmp.isNull() )
667 newLine.append( pt_new );
677 newLine.append( pt_new );
687 QDomNode layerNode = element.firstChild();
689 while ( !layerNode.isNull() )
691 QDomElement e = layerNode.toElement();
694 if ( e.tagName() !=
"layer" )
705 QDomElement s = e.firstChildElement(
"symbol" );
712 QgsDebugMsg(
"symbol layer refused subsymbol: " + s.attribute(
"name" ) );
715 layers.append( layer );
719 layerNode = layerNode.nextSibling();
722 if ( layers.count() == 0 )
728 QString symbolType = element.attribute(
"type" );
731 if ( symbolType ==
"line" )
733 else if ( symbolType ==
"fill" )
735 else if ( symbolType ==
"marker" )
739 QgsDebugMsg(
"unknown symbol type " + symbolType );
743 if ( element.hasAttribute(
"outputUnit" ) )
747 symbol->
setAlpha( element.attribute(
"alpha",
"1.0" ).toDouble() );
754 QString layerClass = element.attribute(
"class" );
755 bool locked = element.attribute(
"locked" ).toInt();
756 int pass = element.attribute(
"pass" ).toInt();
790 QDomElement symEl = doc.createElement(
"symbol" );
792 symEl.setAttribute(
"name", name );
793 symEl.setAttribute(
"alpha", QString::number( symbol->
alpha() ) );
800 QDomElement layerEl = doc.createElement(
"layer" );
801 layerEl.setAttribute(
"class", layer->
layerType() );
802 layerEl.setAttribute(
"locked", layer->
isLocked() );
807 QString subname = QString(
"@%1@%2" ).arg( name ).arg( i );
809 layerEl.appendChild( subEl );
811 symEl.appendChild( layerEl );
824 if ( element.isNull() )
829 QString symbolizerName = element.localName();
831 if ( symbolizerName ==
"PointSymbolizer" )
834 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
835 if ( graphicElem.isNull() )
837 QgsDebugMsg(
"Graphic element not found in PointSymbolizer" );
873 if ( symbolizerName ==
"LineSymbolizer" )
876 QDomElement strokeElem = element.firstChildElement(
"Stroke" );
877 if ( strokeElem.isNull() )
879 QgsDebugMsg(
"Stroke element not found in LineSymbolizer" );
907 if ( symbolizerName ==
"PolygonSymbolizer" )
910 QDomElement fillElem = element.firstChildElement(
"Fill" );
911 QDomElement strokeElem = element.firstChildElement(
"Stroke" );
912 if ( fillElem.isNull() && strokeElem.isNull() )
914 QgsDebugMsg(
"neither Fill nor Stroke element not found in PolygonSymbolizer" );
968 QDomElement fillElem = element.firstChildElement(
"Fill" );
969 if ( fillElem.isNull() )
991 QDomElement strokeElem = element.firstChildElement(
"Stroke" );
992 if ( strokeElem.isNull() )
1010 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1011 if ( graphicElem.isNull() )
1033 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1034 if ( graphicElem.isNull() )
1037 QDomElement externalGraphicElem = graphicElem.firstChildElement(
"ExternalGraphic" );
1038 if ( externalGraphicElem.isNull() )
1042 QDomElement formatElem = externalGraphicElem.firstChildElement(
"Format" );
1043 if ( formatElem.isNull() )
1046 QString format = formatElem.firstChild().nodeValue();
1047 if ( format !=
"image/svg+xml" )
1049 QgsDebugMsg(
"unsupported External Graphic format found: " + format );
1054 QDomElement onlineResourceElem = externalGraphicElem.firstChildElement(
"OnlineResource" );
1055 QDomElement inlineContentElem = externalGraphicElem.firstChildElement(
"InlineContent" );
1056 if ( !onlineResourceElem.isNull() )
1060 else if ( !inlineContentElem.isNull() )
1072 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1073 if ( graphicElem.isNull() )
1076 QDomElement markElem = graphicElem.firstChildElement(
"Mark" );
1077 if ( markElem.isNull() )
1080 QDomElement wellKnownNameElem = markElem.firstChildElement(
"WellKnownName" );
1081 if ( wellKnownNameElem.isNull() )
1090 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1091 if ( graphicElem.isNull() )
1094 QDomElement markElem = graphicElem.firstChildElement(
"Mark" );
1095 if ( markElem.isNull() )
1099 QDomElement formatElem = markElem.firstChildElement(
"Format" );
1100 if ( formatElem.isNull() )
1103 QString format = formatElem.firstChild().nodeValue();
1104 if ( format !=
"ttf" )
1106 QgsDebugMsg(
"unsupported Graphic Mark format found: " + format );
1111 QDomElement onlineResourceElem = markElem.firstChildElement(
"OnlineResource" );
1112 QDomElement inlineContentElem = markElem.firstChildElement(
"InlineContent" );
1113 if ( !onlineResourceElem.isNull() )
1116 QDomElement markIndexElem = markElem.firstChildElement(
"MarkIndex" );
1117 if ( !markIndexElem.isNull() )
1120 else if ( !inlineContentElem.isNull() )
1135 QDomElement graphicElem = element.firstChildElement(
"Graphic" );
1136 if ( graphicElem.isNull() )
1140 for ( QgsStringMap::iterator it = vendorOptions.begin(); it != vendorOptions.end(); ++it )
1142 if ( it.key() ==
"widthHeightFactor" )
1153 QDomElement strokeElem = element.firstChildElement(
"Stroke" );
1154 if ( strokeElem.isNull() )
1157 QDomElement graphicStrokeElem = strokeElem.firstChildElement(
"GraphicStroke" );
1158 if ( graphicStrokeElem.isNull() )
1166 QDomElement fillElem = element.firstChildElement(
"Fill" );
1167 if ( fillElem.isNull() )
1170 QDomElement graphicFillElem = fillElem.firstChildElement(
"GraphicFill" );
1171 if ( graphicFillElem.isNull() )
1174 QDomElement graphicElem = graphicFillElem.firstChildElement(
"Graphic" );
1175 if ( graphicElem.isNull() )
1181 QColor fillColor, borderColor;
1182 double size, borderWidth;
1186 if ( name !=
"horline" )
1194 double angle = angleFunc.toDouble( &ok );
1195 if ( !ok || angle == 0 )
1203 Q_UNUSED( element );
1209 QDomElement fillElem = element.firstChildElement(
"Fill" );
1210 if ( fillElem.isNull() )
1213 QDomElement graphicFillElem = fillElem.firstChildElement(
"GraphicFill" );
1214 if ( graphicFillElem.isNull() )
1234 QDomElement fillElem = element.firstChildElement(
"Fill" );
1235 QDomElement strokeElem = element.firstChildElement(
"Stroke" );
1239 bool validFill =
false, validBorder =
false;
1244 Qt::BrushStyle fillStyle;
1246 if (
fillFromSld( fillElem, fillStyle, fillColor ) )
1252 Qt::PenStyle borderStyle;
1253 double borderWidth = 1.0, dashOffset = 0.0;
1254 QVector<qreal> customDashPattern;
1256 if (
lineFromSld( strokeElem, borderStyle, borderColor, borderWidth,
1257 0, 0, &customDashPattern, &dashOffset ) )
1260 if ( validFill || validBorder )
1263 map[
"name"] =
"square";
1264 map[
"color"] =
encodeColor( validFill ? fillColor : Qt::transparent );
1265 map[
"color_border"] =
encodeColor( validBorder ? borderColor : Qt::transparent );
1266 map[
"size"] = QString::number( 6 );
1267 map[
"angle"] = QString::number( 0 );
1275 bool validFill =
false, validBorder =
false;
1278 QString name, format;
1280 QColor fillColor, borderColor;
1281 double borderWidth = 1.0,
size = 0.0,
angle = 0.0;
1282 QPointF anchor, offset;
1285 QDomElement graphicFillElem = fillElem.firstChildElement(
"GraphicFill" );
1286 if ( !graphicFillElem.isNull() )
1289 QDomElement graphicElem = graphicFillElem.firstChildElement(
"Graphic" );
1290 if ( !graphicElem.isNull() )
1296 QDomElement graphicChildElem = graphicElem.firstChildElement();
1297 while ( !graphicChildElem.isNull() )
1299 if ( graphicChildElem.localName() ==
"Mark" )
1302 QDomElement wellKnownNameElem = graphicChildElem.firstChildElement(
"WellKnownName" );
1303 if ( !wellKnownNameElem.isNull() )
1305 name = wellKnownNameElem.firstChild().nodeValue();
1311 if ( graphicChildElem.localName() ==
"ExternalGraphic" || graphicChildElem.localName() ==
"Mark" )
1314 QDomElement formatElem = graphicChildElem.firstChildElement(
"Format" );
1315 if ( formatElem.isNull() )
1318 format = formatElem.firstChild().nodeValue();
1322 if ( graphicChildElem.localName() ==
"ExternalGraphic" && format !=
"image/svg+xml" )
1327 if ( graphicChildElem.localName() ==
"Mark" && format !=
"ttf" )
1331 QDomElement onlineResourceElem = graphicChildElem.firstChildElement(
"OnlineResource" );
1332 QDomElement inlineContentElem = graphicChildElem.firstChildElement(
"InlineContent" );
1334 if ( !onlineResourceElem.isNull() )
1336 name = onlineResourceElem.attributeNS(
"http://www.w3.org/1999/xlink",
"href" );
1338 if ( graphicChildElem.localName() ==
"Mark" && format ==
"ttf" )
1341 if ( name.startsWith(
"ttf://" ) )
1342 name = name.mid( 6 );
1345 QDomElement markIndexElem = graphicChildElem.firstChildElement(
"MarkIndex" );
1346 if ( markIndexElem.isNull() )
1350 int v = markIndexElem.firstChild().nodeValue().toInt( &ok );
1360 else if ( !inlineContentElem.isNull() )
1369 if ( graphicChildElem.localName() ==
"Mark" )
1378 if ( found && graphicChildElem.localName() ==
"Mark" )
1385 Qt::BrushStyle markFillStyle;
1387 QDomElement markFillElem = graphicChildElem.firstChildElement(
"Fill" );
1388 if (
fillFromSld( markFillElem, markFillStyle, fillColor ) )
1393 Qt::PenStyle borderStyle;
1394 double borderWidth = 1.0, dashOffset = 0.0;
1395 QVector<qreal> customDashPattern;
1397 QDomElement markStrokeElem = graphicChildElem.firstChildElement(
"Stroke" );
1398 if (
lineFromSld( markStrokeElem, borderStyle, borderColor, borderWidth,
1399 0, 0, &customDashPattern, &dashOffset ) )
1406 QDomElement opacityElem = graphicElem.firstChildElement(
"Opacity" );
1407 if ( !opacityElem.isNull() )
1408 fillColor.setAlpha(
decodeSldAlpha( opacityElem.firstChild().nodeValue() ) );
1410 QDomElement sizeElem = graphicElem.firstChildElement(
"Size" );
1411 if ( !sizeElem.isNull() )
1414 double v = sizeElem.firstChild().nodeValue().toDouble( &ok );
1423 double v = angleFunc.toDouble( &ok );
1433 if ( validFill || validBorder )
1435 if ( format ==
"image/svg+xml" )
1439 map[
"fill"] = fillColor.name();
1440 map[
"outline"] = borderColor.name();
1441 map[
"outline-width"] = QString::number( borderWidth );
1443 map[
"size"] = QString::number(
size );
1445 map[
"angle"] = QString::number(
angle );
1446 if ( !offset.isNull() )
1450 else if ( format ==
"ttf" )
1454 map[
"chr"] = markIndex;
1455 map[
"color"] =
encodeColor( validFill ? fillColor : Qt::transparent );
1457 map[
"size"] = QString::number(
size );
1459 map[
"angle"] = QString::number(
angle );
1460 if ( !offset.isNull() )
1467 if ( layers.isEmpty() )
1470 layerList << layers;
1477 QString patternName;
1478 switch ( brushStyle )
1483 case Qt::SolidPattern:
1484 if ( color.isValid() )
1487 if ( color.alpha() < 255 )
1492 case Qt::CrossPattern:
1493 case Qt::DiagCrossPattern:
1494 case Qt::HorPattern:
1495 case Qt::VerPattern:
1496 case Qt::BDiagPattern:
1497 case Qt::FDiagPattern:
1498 case Qt::Dense1Pattern:
1499 case Qt::Dense2Pattern:
1500 case Qt::Dense3Pattern:
1501 case Qt::Dense4Pattern:
1502 case Qt::Dense5Pattern:
1503 case Qt::Dense6Pattern:
1504 case Qt::Dense7Pattern:
1509 element.appendChild( doc.createComment( QString(
"Qt::BrushStyle '%1'' not supported yet" ).arg( brushStyle ) ) );
1513 QDomElement graphicFillElem = doc.createElement(
"se:GraphicFill" );
1514 element.appendChild( graphicFillElem );
1516 QDomElement graphicElem = doc.createElement(
"se:Graphic" );
1517 graphicFillElem.appendChild( graphicElem );
1519 QColor fillColor = patternName.startsWith(
"brush://" ) ? color : QColor();
1520 QColor borderColor = !patternName.startsWith(
"brush://" ) ? color : QColor();
1530 brushStyle = Qt::SolidPattern;
1531 color = QColor(
"#808080" );
1533 if ( element.isNull() )
1535 brushStyle = Qt::NoBrush;
1540 QDomElement graphicFillElem = element.firstChildElement(
"GraphicFill" );
1542 if ( graphicFillElem.isNull() )
1545 for ( QgsStringMap::iterator it = svgParams.begin(); it != svgParams.end(); ++it )
1547 QgsDebugMsg( QString(
"found SvgParameter %1: %2" ).arg( it.key() ).arg( it.value() ) );
1549 if ( it.key() ==
"fill" )
1550 color = QColor( it.value() );
1551 else if ( it.key() ==
"fill-opacity" )
1557 QDomElement graphicElem = graphicFillElem.firstChildElement(
"Graphic" );
1558 if ( graphicElem.isNull() )
1561 QString patternName =
"square";
1562 QColor fillColor, borderColor;
1563 double borderWidth,
size;
1568 if ( brushStyle == Qt::NoBrush )
1571 QColor c = patternName.startsWith(
"brush://" ) ? fillColor : borderColor;
1580 Qt::PenStyle penStyle, QColor color,
double width,
1581 const Qt::PenJoinStyle *penJoinStyle,
const Qt::PenCapStyle *penCapStyle,
1582 const QVector<qreal> *customDashPattern,
double dashOffset )
1584 QVector<qreal> dashPattern;
1585 const QVector<qreal> *pattern = &dashPattern;
1587 if ( penStyle == Qt::CustomDashLine && !customDashPattern )
1589 element.appendChild( doc.createComment(
"WARNING: Custom dash pattern required but not provided. Using default dash pattern." ) );
1590 penStyle = Qt::DashLine;
1602 dashPattern.push_back( 4.0 );
1603 dashPattern.push_back( 2.0 );
1606 dashPattern.push_back( 1.0 );
1607 dashPattern.push_back( 2.0 );
1609 case Qt::DashDotLine:
1610 dashPattern.push_back( 4.0 );
1611 dashPattern.push_back( 2.0 );
1612 dashPattern.push_back( 1.0 );
1613 dashPattern.push_back( 2.0 );
1615 case Qt::DashDotDotLine:
1616 dashPattern.push_back( 4.0 );
1617 dashPattern.push_back( 2.0 );
1618 dashPattern.push_back( 1.0 );
1619 dashPattern.push_back( 2.0 );
1620 dashPattern.push_back( 1.0 );
1621 dashPattern.push_back( 2.0 );
1624 case Qt::CustomDashLine:
1625 Q_ASSERT( customDashPattern );
1626 pattern = customDashPattern;
1630 element.appendChild( doc.createComment( QString(
"Qt::BrushStyle '%1'' not supported yet" ).arg( penStyle ) ) );
1634 if ( color.isValid() )
1637 if ( color.alpha() < 255 )
1647 if ( pattern->size() > 0 )
1657 Qt::PenStyle &penStyle, QColor &color,
double &width,
1658 Qt::PenJoinStyle *penJoinStyle, Qt::PenCapStyle *penCapStyle,
1659 QVector<qreal> *customDashPattern,
double *dashOffset )
1663 penStyle = Qt::SolidLine;
1664 color = QColor(
"#000000" );
1667 *penJoinStyle = Qt::BevelJoin;
1669 *penCapStyle = Qt::SquareCap;
1670 if ( customDashPattern )
1671 customDashPattern->clear();
1675 if ( element.isNull() )
1677 penStyle = Qt::NoPen;
1683 for ( QgsStringMap::iterator it = svgParams.begin(); it != svgParams.end(); ++it )
1685 QgsDebugMsg( QString(
"found SvgParameter %1: %2" ).arg( it.key() ).arg( it.value() ) );
1687 if ( it.key() ==
"stroke" )
1689 color = QColor( it.value() );
1691 else if ( it.key() ==
"stroke-opacity" )
1695 else if ( it.key() ==
"stroke-width" )
1698 double w = it.value().toDouble( &ok );
1702 else if ( it.key() ==
"stroke-linejoin" && penJoinStyle )
1706 else if ( it.key() ==
"stroke-linecap" && penCapStyle )
1710 else if ( it.key() ==
"stroke-dasharray" )
1713 if ( dashPattern.size() > 0 )
1717 bool dashPatternFound =
false;
1719 if ( dashPattern.count() == 2 )
1721 if ( dashPattern.at( 0 ) == 4.0 &&
1722 dashPattern.at( 1 ) == 2.0 )
1724 penStyle = Qt::DashLine;
1725 dashPatternFound =
true;
1727 else if ( dashPattern.at( 0 ) == 1.0 &&
1728 dashPattern.at( 1 ) == 2.0 )
1730 penStyle = Qt::DotLine;
1731 dashPatternFound =
true;
1734 else if ( dashPattern.count() == 4 )
1736 if ( dashPattern.at( 0 ) == 4.0 &&
1737 dashPattern.at( 1 ) == 2.0 &&
1738 dashPattern.at( 2 ) == 1.0 &&
1739 dashPattern.at( 3 ) == 2.0 )
1741 penStyle = Qt::DashDotLine;
1742 dashPatternFound =
true;
1745 else if ( dashPattern.count() == 6 )
1747 if ( dashPattern.at( 0 ) == 4.0 &&
1748 dashPattern.at( 1 ) == 2.0 &&
1749 dashPattern.at( 2 ) == 1.0 &&
1750 dashPattern.at( 3 ) == 2.0 &&
1751 dashPattern.at( 4 ) == 1.0 &&
1752 dashPattern.at( 5 ) == 2.0 )
1754 penStyle = Qt::DashDotDotLine;
1755 dashPatternFound =
true;
1760 if ( !dashPatternFound )
1762 if ( customDashPattern )
1764 penStyle = Qt::CustomDashLine;
1765 *customDashPattern = dashPattern;
1769 QgsDebugMsg(
"custom dash pattern required but not provided. Using default dash pattern." );
1770 penStyle = Qt::DashLine;
1775 else if ( it.key() ==
"stroke-dashoffset" && dashOffset )
1778 double d = it.value().toDouble( &ok );
1788 QString path, QString mime,
1789 QColor color,
double size )
1791 QDomElement externalGraphicElem = doc.createElement(
"se:ExternalGraphic" );
1792 element.appendChild( externalGraphicElem );
1801 QDomElement sizeElem = doc.createElement(
"se:Size" );
1802 sizeElem.appendChild( doc.createTextNode( QString::number( size ) ) );
1803 element.appendChild( sizeElem );
1808 QString &path, QString &mime,
1809 QColor &color,
double &
size )
1814 QDomElement externalGraphicElem = element.firstChildElement(
"ExternalGraphic" );
1815 if ( externalGraphicElem.isNull() )
1820 QDomElement sizeElem = element.firstChildElement(
"Size" );
1821 if ( !sizeElem.isNull() )
1824 double s = sizeElem.firstChild().nodeValue().toDouble( &ok );
1833 QString path, QString format,
int *markIndex,
1834 QColor color,
double size )
1836 QDomElement markElem = doc.createElement(
"se:Mark" );
1837 element.appendChild( markElem );
1843 QDomElement markIndexElem = doc.createElement(
"se:MarkIndex" );
1844 markIndexElem.appendChild( doc.createTextNode( QString::number( *markIndex ) ) );
1845 markElem.appendChild( markIndexElem );
1849 QDomElement fillElem = doc.createElement(
"se:Fill" );
1850 fillToSld( doc, fillElem, Qt::SolidPattern, color );
1851 markElem.appendChild( fillElem );
1856 QDomElement sizeElem = doc.createElement(
"se:Size" );
1857 sizeElem.appendChild( doc.createTextNode( QString::number( size ) ) );
1858 element.appendChild( sizeElem );
1863 QString &path, QString &format,
int &markIndex,
1864 QColor &color,
double &
size )
1872 QDomElement markElem = element.firstChildElement(
"Mark" );
1873 if ( markElem.isNull() )
1878 QDomElement markIndexElem = markElem.firstChildElement(
"MarkIndex" );
1879 if ( !markIndexElem.isNull() )
1882 int i = markIndexElem.firstChild().nodeValue().toInt( &ok );
1888 QDomElement fillElem = markElem.firstChildElement(
"Fill" );
1889 Qt::BrushStyle b = Qt::SolidPattern;
1894 QDomElement sizeElem = element.firstChildElement(
"Size" );
1895 if ( !sizeElem.isNull() )
1898 double s = sizeElem.firstChild().nodeValue().toDouble( &ok );
1907 QString name, QColor color, QColor borderColor,
1908 double borderWidth,
double size )
1910 QDomElement markElem = doc.createElement(
"se:Mark" );
1911 element.appendChild( markElem );
1913 QDomElement wellKnownNameElem = doc.createElement(
"se:WellKnownName" );
1914 wellKnownNameElem.appendChild( doc.createTextNode( name ) );
1915 markElem.appendChild( wellKnownNameElem );
1918 if ( color.isValid() )
1920 QDomElement fillElem = doc.createElement(
"se:Fill" );
1921 fillToSld( doc, fillElem, Qt::SolidPattern, color );
1922 markElem.appendChild( fillElem );
1926 if ( borderColor.isValid() )
1928 QDomElement strokeElem = doc.createElement(
"se:Stroke" );
1929 lineToSld( doc, strokeElem, Qt::SolidLine, borderColor, borderWidth );
1930 markElem.appendChild( strokeElem );
1936 QDomElement sizeElem = doc.createElement(
"se:Size" );
1937 sizeElem.appendChild( doc.createTextNode( QString::number( size ) ) );
1938 element.appendChild( sizeElem );
1943 QString &name, QColor &color, QColor &borderColor,
1944 double &borderWidth,
double &
size )
1950 borderColor = QColor(
"#000000" );
1954 QDomElement markElem = element.firstChildElement(
"Mark" );
1955 if ( markElem.isNull() )
1958 QDomElement wellKnownNameElem = markElem.firstChildElement(
"WellKnownName" );
1959 if ( !wellKnownNameElem.isNull() )
1961 name = wellKnownNameElem.firstChild().nodeValue();
1962 QgsDebugMsg(
"found Mark with well known name: " + name );
1966 QDomElement fillElem = markElem.firstChildElement(
"Fill" );
1967 Qt::BrushStyle b = Qt::SolidPattern;
1972 QDomElement strokeElem = markElem.firstChildElement(
"Stroke" );
1973 Qt::PenStyle p = Qt::SolidLine;
1974 lineFromSld( strokeElem, p, borderColor, borderWidth );
1978 QDomElement sizeElem = element.firstChildElement(
"Size" );
1979 if ( !sizeElem.isNull() )
1982 double s = sizeElem.firstChild().nodeValue().toDouble( &ok );
1992 if ( !rotationFunc.isEmpty() )
1994 QDomElement rotationElem = doc.createElement(
"se:Rotation" );
1996 element.appendChild( rotationElem );
2002 QDomElement rotationElem = element.firstChildElement(
"Rotation" );
2003 if ( !rotationElem.isNull() )
2013 if ( !alphaFunc.isEmpty() )
2015 QDomElement opacityElem = doc.createElement(
"se:Opacity" );
2017 element.appendChild( opacityElem );
2023 QDomElement opacityElem = element.firstChildElement(
"Opacity" );
2024 if ( !opacityElem.isNull() )
2033 if ( offset.isNull() )
2036 QDomElement displacementElem = doc.createElement(
"se:Displacement" );
2037 element.appendChild( displacementElem );
2039 QDomElement dispXElem = doc.createElement(
"se:DisplacementX" );
2040 dispXElem.appendChild( doc.createTextNode( QString::number( offset.x() ) ) );
2042 QDomElement dispYElem = doc.createElement(
"se:DisplacementY" );
2043 dispYElem.appendChild( doc.createTextNode( QString::number( offset.y() ) ) );
2045 displacementElem.appendChild( dispXElem );
2046 displacementElem.appendChild( dispYElem );
2051 offset = QPointF( 0, 0 );
2053 QDomElement displacementElem = element.firstChildElement(
"Displacement" );
2054 if ( displacementElem.isNull() )
2057 QDomElement dispXElem = displacementElem.firstChildElement(
"DisplacementX" );
2058 if ( !dispXElem.isNull() )
2061 double offsetX = dispXElem.firstChild().nodeValue().toDouble( &ok );
2063 offset.setX( offsetX );
2066 QDomElement dispYElem = displacementElem.firstChildElement(
"DisplacementY" );
2067 if ( !dispYElem.isNull() )
2070 double offsetY = dispYElem.firstChild().nodeValue().toDouble( &ok );
2072 offset.setY( offsetY );
2079 QString label, QFont font,
2080 QColor color,
double size )
2082 QDomElement labelElem = doc.createElement(
"se:Label" );
2083 labelElem.appendChild( doc.createTextNode( label ) );
2084 element.appendChild( labelElem );
2086 QDomElement fontElem = doc.createElement(
"se:Font" );
2087 element.appendChild( fontElem );
2091 fontElem.appendChild( createSldParameterElement( doc,
"font-style",
encodeSldFontStyle( font.style() ) ) );
2092 fontElem.appendChild( createSldParameterElement( doc,
"font-weight",
encodeSldFontWeight( font.weight() ) ) );
2097 if ( color.isValid() )
2099 QDomElement fillElem = doc.createElement(
"Fill" );
2100 fillToSld( doc, fillElem, Qt::SolidPattern, color );
2101 element.appendChild( fillElem );
2106 Qt::PenJoinStyle joinStyle,
2107 Qt::PenCapStyle capStyle,
2109 const QVector<qreal>* dashPattern )
2112 penStyle.append(
"PEN(" );
2113 penStyle.append(
"c:" );
2114 penStyle.append( c.name() );
2115 penStyle.append(
",w:" );
2117 penStyle.append( QString::number( width * mmScaleFactor ) );
2118 penStyle.append(
"mm" );
2121 if ( dashPattern && dashPattern->size() > 0 )
2123 penStyle.append(
",p:\"" );
2124 QVector<qreal>::const_iterator pIt = dashPattern->constBegin();
2125 for ( ; pIt != dashPattern->constEnd(); ++pIt )
2127 if ( pIt != dashPattern->constBegin() )
2129 penStyle.append(
" " );
2131 penStyle.append( QString::number( *pIt * mapUnitScaleFactor ) );
2132 penStyle.append(
"g" );
2134 penStyle.append(
"\"" );
2138 penStyle.append(
",cap:" );
2142 penStyle.append(
"p" );
2145 penStyle.append(
"r" );
2149 penStyle.append(
"b" );
2153 penStyle.append(
",j:" );
2154 switch ( joinStyle )
2157 penStyle.append(
"b" );
2160 penStyle.append(
"r" );
2164 penStyle.append(
"m" );
2170 penStyle.append(
",dp:" );
2171 penStyle.append( QString::number( offset * mapUnitScaleFactor ) );
2172 penStyle.append(
"g" );
2175 penStyle.append(
")" );
2182 brushStyle.append(
"BRUSH(" );
2183 brushStyle.append(
"fc:" );
2184 brushStyle.append( fillColor.name() );
2185 brushStyle.append(
")" );
2191 if ( geomFunc.isEmpty() )
2194 QDomElement geometryElem = doc.createElement(
"Geometry" );
2195 element.appendChild( geometryElem );
2225 QDomElement geometryElem = element.firstChildElement(
"Geometry" );
2226 if ( geometryElem.isNull() )
2238 element.appendChild( doc.createComment(
"Parser Error: " + expr.
parserErrorString() +
" - Expression was: " + function ) );
2242 if ( !filterElem.isNull() )
2243 element.appendChild( filterElem );
2262 function = expr->
dump();
2270 QString path, QString format )
2275 QUrl url( relpath );
2276 if ( !url.isValid() || url.scheme().isEmpty() )
2278 url.setUrl( QUrl::fromLocalFile( relpath ).toString() );
2281 QDomElement onlineResourceElem = doc.createElement(
"se:OnlineResource" );
2282 onlineResourceElem.setAttribute(
"xlink:type",
"simple" );
2283 onlineResourceElem.setAttribute(
"xlink:href", url.toString() );
2284 element.appendChild( onlineResourceElem );
2286 QDomElement formatElem = doc.createElement(
"se:Format" );
2287 formatElem.appendChild( doc.createTextNode( format ) );
2288 element.appendChild( formatElem );
2295 QDomElement onlineResourceElem = element.firstChildElement(
"OnlineResource" );
2296 if ( onlineResourceElem.isNull() )
2299 path = onlineResourceElem.attributeNS(
"http://www.w3.org/1999/xlink",
"href" );
2301 QDomElement formatElem = element.firstChildElement(
"Format" );
2302 if ( formatElem.isNull() )
2305 format = formatElem.firstChild().nodeValue();
2312 QDomElement nodeElem = doc.createElement(
"se:SvgParameter" );
2313 nodeElem.setAttribute(
"name", name );
2314 nodeElem.appendChild( doc.createTextNode( value ) );
2322 QDomElement paramElem = element.firstChildElement();
2323 while ( !paramElem.isNull() )
2325 if ( paramElem.localName() ==
"SvgParameter" || paramElem.localName() ==
"CssParameter" )
2327 QString name = paramElem.attribute(
"name" );
2328 QString value = paramElem.firstChild().nodeValue();
2330 if ( !name.isEmpty() && !value.isEmpty() )
2331 params[ name ] = value;
2334 paramElem = paramElem.nextSiblingElement();
2342 QDomElement nodeElem = doc.createElement(
"VendorOption" );
2343 nodeElem.setAttribute(
"name", name );
2344 nodeElem.appendChild( doc.createTextNode( value ) );
2352 QDomElement paramElem = element.firstChildElement(
"VendorOption" );
2353 while ( !paramElem.isNull() )
2355 QString name = paramElem.attribute(
"name" );
2356 QString value = paramElem.firstChild().nodeValue();
2358 if ( !name.isEmpty() && !value.isEmpty() )
2359 params[ name ] = value;
2361 paramElem = paramElem.nextSiblingElement(
"VendorOption" );
2371 QDomElement e = element.firstChildElement();
2372 while ( !e.isNull() )
2374 if ( e.tagName() !=
"prop" )
2380 QString propKey = e.attribute(
"k" );
2381 QString propValue = e.attribute(
"v" );
2382 props[propKey] = propValue;
2384 e = e.nextSiblingElement();
2392 for ( QgsStringMap::iterator it = props.begin(); it != props.end(); ++it )
2394 QDomElement propEl = doc.createElement(
"prop" );
2395 propEl.setAttribute(
"k", it.key() );
2396 propEl.setAttribute(
"v", it.value() );
2397 element.appendChild( propEl );
2406 QDomElement e = element.firstChildElement();
2408 while ( !e.isNull() )
2410 if ( e.tagName() ==
"symbol" )
2413 if ( symbol != NULL )
2414 symbols.insert( e.attribute(
"name" ), symbol );
2420 e = e.nextSiblingElement();
2427 QStringList subsymbols;
2429 for ( QMap<QString, QgsSymbolV2*>::iterator it = symbols.begin(); it != symbols.end(); ++it )
2431 if ( it.key()[0] !=
'@' )
2435 subsymbols.append( it.key() );
2437 QStringList parts = it.key().split(
"@" );
2438 if ( parts.count() < 3 )
2440 QgsDebugMsg(
"found subsymbol with invalid name: " + it.key() );
2444 QString symname = parts[1];
2445 int symlayer = parts[2].toInt();
2447 if ( !symbols.contains( symname ) )
2449 QgsDebugMsg(
"subsymbol references invalid symbol: " + symname );
2457 QgsDebugMsg(
"subsymbol references invalid symbol layer: " + QString::number( symlayer ) );
2466 QgsDebugMsg(
"symbol layer refused subsymbol: " + it.key() );
2473 for (
int i = 0; i < subsymbols.count(); i++ )
2474 symbols.take( subsymbols[i] );
2481 QDomElement symbolsElem = doc.createElement( tagName );
2484 for ( QMap<QString, QgsSymbolV2*>::iterator its = symbols.begin(); its != symbols.end(); ++its )
2486 QDomElement symEl =
saveSymbol( its.key(), its.value(), doc );
2487 symbolsElem.appendChild( symEl );
2495 foreach ( QString name, symbols.keys() )
2497 delete symbols.value( name );
2505 QString rampType = element.attribute(
"type" );
2510 if ( rampType ==
"gradient" )
2512 else if ( rampType ==
"random" )
2514 else if ( rampType ==
"colorbrewer" )
2516 else if ( rampType ==
"cpt-city" )
2520 QgsDebugMsg(
"unknown colorramp type " + rampType );
2528 QDomElement rampEl = doc.createElement(
"colorramp" );
2529 rampEl.setAttribute(
"type", ramp->
type() );
2530 rampEl.setAttribute(
"name", name );
2540 if ( colorStr.startsWith(
"rgb(" ) )
2542 colorStr = colorStr.mid( 4, colorStr.size() - 5 ).trimmed();
2544 QStringList p = colorStr.split( QChar(
',' ) );
2545 if ( p.count() != 3 )
2547 return QColor( p[0].toInt(), p[1].toInt(), p[2].toInt() );
2596 if ( p && p->device() )
2615 QImage::Format format = image->format();
2616 if ( format != QImage::Format_ARGB32_Premultiplied && format != QImage::Format_ARGB32 )
2623 for (
int heightIndex = 0; heightIndex < image->height(); ++heightIndex )
2625 QRgb* scanLine = ( QRgb* )image->scanLine( heightIndex );
2626 for (
int widthIndex = 0; widthIndex < image->width(); ++widthIndex )
2628 myRgb = scanLine[widthIndex];
2629 if ( format == QImage::Format_ARGB32_Premultiplied )
2630 scanLine[widthIndex] = qRgba( alpha * qRed( myRgb ), alpha * qGreen( myRgb ), alpha * qBlue( myRgb ), alpha * qAlpha( myRgb ) );
2632 scanLine[widthIndex] = qRgba( qRed( myRgb ), qGreen( myRgb ), qBlue( myRgb ), alpha * qAlpha( myRgb ) );
2640 int tab[] = { 14, 10, 8, 6, 5, 5, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2 };
2641 int alpha = ( radius < 1 ) ? 16 : ( radius > 17 ) ? 1 : tab[radius-1];
2643 if ( image.format() != QImage::Format_ARGB32_Premultiplied
2644 && image.format() != QImage::Format_RGB32 )
2646 image = image.convertToFormat( QImage::Format_ARGB32_Premultiplied );
2649 int r1 = rect.top();
2650 int r2 = rect.bottom();
2651 int c1 = rect.left();
2652 int c2 = rect.right();
2654 int bpl = image.bytesPerLine();
2662 i1 = i2 = ( QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3 );
2664 for (
int col = c1; col <= c2; col++ )
2666 p = image.scanLine( r1 ) + col * 4;
2667 for (
int i = i1; i <= i2; i++ )
2668 rgba[i] = p[i] << 4;
2671 for (
int j = r1; j < r2; j++, p += bpl )
2672 for (
int i = i1; i <= i2; i++ )
2673 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
2676 for (
int row = r1; row <= r2; row++ )
2678 p = image.scanLine( row ) + c1 * 4;
2679 for (
int i = i1; i <= i2; i++ )
2680 rgba[i] = p[i] << 4;
2683 for (
int j = c1; j < c2; j++, p += 4 )
2684 for (
int i = i1; i <= i2; i++ )
2685 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
2688 for (
int col = c1; col <= c2; col++ )
2690 p = image.scanLine( r2 ) + col * 4;
2691 for (
int i = i1; i <= i2; i++ )
2692 rgba[i] = p[i] << 4;
2695 for (
int j = r1; j < r2; j++, p -= bpl )
2696 for (
int i = i1; i <= i2; i++ )
2697 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
2700 for (
int row = r1; row <= r2; row++ )
2702 p = image.scanLine( row ) + c2 * 4;
2703 for (
int i = i1; i <= i2; i++ )
2704 rgba[i] = p[i] << 4;
2707 for (
int j = c1; j < c2; j++, p -= 4 )
2708 for (
int i = i1; i <= i2; i++ )
2709 p[i] = ( rgba[i] += (( p[i] << 4 ) - rgba[i] ) * alpha / 16 ) >> 4;
2714 static bool _QVariantLessThan(
const QVariant& lhs,
const QVariant& rhs )
2716 switch ( lhs.type() )
2719 return lhs.toInt() < rhs.toInt();
2720 case QVariant::UInt:
2721 return lhs.toUInt() < rhs.toUInt();
2722 case QVariant::LongLong:
2723 return lhs.toLongLong() < rhs.toLongLong();
2724 case QVariant::ULongLong:
2725 return lhs.toULongLong() < rhs.toULongLong();
2726 case QVariant::Double:
2727 return lhs.toDouble() < rhs.toDouble();
2728 case QVariant::Char:
2729 return lhs.toChar() < rhs.toChar();
2730 case QVariant::Date:
2731 return lhs.toDate() < rhs.toDate();
2732 case QVariant::Time:
2733 return lhs.toTime() < rhs.toTime();
2734 case QVariant::DateTime:
2735 return lhs.toDateTime() < rhs.toDateTime();
2737 return QString::localeAwareCompare( lhs.toString(), rhs.toString() ) < 0;
2741 static bool _QVariantGreaterThan(
const QVariant& lhs,
const QVariant& rhs )
2743 return ! _QVariantLessThan( lhs, rhs );
2749 if ( order == Qt::AscendingOrder )
2763 double dx = directionPoint.x() - startPoint.x();
2764 double dy = directionPoint.y() - startPoint.y();
2765 double length = sqrt( dx * dx + dy * dy );
2766 double scaleFactor = distance / length;
2767 return QPointF( startPoint.x() + dx * scaleFactor, startPoint.y() + dy * scaleFactor );
2777 for (
int i = 0; i < svgPaths.size(); i++ )
2779 QDir dir( svgPaths[i] );
2780 foreach ( QString item, dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
2782 svgPaths.insert( i + 1, dir.path() +
"/" + item );
2785 foreach ( QString item, dir.entryList( QStringList(
"*.svg" ), QDir::Files ) )
2788 list.append( dir.path() +
"/" + item );
2800 QStringList svgPaths;
2801 svgPaths.append( directory );
2803 for (
int i = 0; i < svgPaths.size(); i++ )
2805 QDir dir( svgPaths[i] );
2806 foreach ( QString item, dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
2808 svgPaths.insert( i + 1, dir.path() +
"/" + item );
2811 foreach ( QString item, dir.entryList( QStringList(
"*.svg" ), QDir::Files ) )
2813 list.append( dir.path() +
"/" + item );
2825 if ( QFile( name ).exists() )
2826 return QFileInfo( name ).canonicalFilePath();
2829 if ( name.contains(
"://" ) )
2832 if ( url.isValid() && !url.scheme().isEmpty() )
2834 if ( url.scheme().compare(
"file", Qt::CaseInsensitive ) == 0 )
2837 name = url.toLocalFile();
2838 if ( QFile( name ).exists() )
2840 return QFileInfo( name ).canonicalFilePath();
2854 for (
int i = 0; i < svgPaths.size(); i++ )
2856 QString svgPath = svgPaths[i];
2857 if ( svgPath.endsWith( QString(
"/" ) ) )
2863 QFileInfo myInfo( name );
2864 QString myFileName = myInfo.fileName();
2865 QString myLowestDir = myInfo.dir().dirName();
2866 QString myLocalPath = svgPath + QString( myLowestDir.isEmpty() ?
"" :
"/" + myLowestDir ) +
"/" + myFileName;
2868 QgsDebugMsg(
"Alternative svg path: " + myLocalPath );
2869 if ( QFile( myLocalPath ).exists() )
2872 return QFileInfo( myLocalPath ).canonicalFilePath();
2874 else if ( myInfo.isRelative() )
2877 QString alternatePath = pfi.canonicalPath() + QDir::separator() + name;
2878 if ( pfi.exists() && QFile( alternatePath ).exists() )
2881 return QFileInfo( alternatePath ).canonicalFilePath();
2891 QgsDebugMsg(
"Computed alternate path but no svg there either" );
2901 QFileInfo fi( path );
2905 path = fi.canonicalFilePath();
2909 bool isInSvgPathes =
false;
2910 for (
int i = 0; i < svgPaths.size(); i++ )
2912 QString dir = QFileInfo( svgPaths[i] ).canonicalFilePath();
2914 if ( !dir.isEmpty() && path.startsWith( dir ) )
2916 path = path.mid( dir.size() );
2917 isInSvgPathes =
true;
2922 if ( isInSvgPathes )