32 #include <QDomDocument>
40 mLowerValue( lvalue ),
41 mUpperValue( uvalue ),
44 mPointSymbolName(
"hard:circle" ),
46 mSizeInMapUnits( false ),
47 mPointSymbolImage( 1, 1, QImage::Format_ARGB32_Premultiplied ),
49 mCacheUpToDate( false ),
50 mCacheUpToDate2( false ),
51 mRotationClassificationField( -1 ),
52 mScaleClassificationField( -1 ),
60 mLowerValue( lvalue ),
61 mUpperValue( uvalue ),
66 mPointSymbolName(
"hard:circle" ),
68 mSizeInMapUnits( false ),
69 mPointSymbolImage( 1, 1, QImage::Format_ARGB32_Premultiplied ),
71 mCacheUpToDate( false ),
72 mCacheUpToDate2( false ),
73 mRotationClassificationField( -1 ),
74 mScaleClassificationField( -1 ),
81 : mPointSymbolName(
"hard:circle" ),
83 mSizeInMapUnits( false ),
84 mPointSymbolImage( 1, 1, QImage::Format_ARGB32_Premultiplied ),
86 mCacheUpToDate( false ),
87 mCacheUpToDate2( false ),
88 mRotationClassificationField( -1 ),
89 mScaleClassificationField( -1 ),
99 mPointSymbolName(
"hard:circle" ),
101 mSizeInMapUnits( false ),
102 mPointSymbolImage( 1, 1, QImage::Format_ARGB32_Premultiplied ),
104 mCacheUpToDate( false ),
105 mCacheUpToDate2( false ),
106 mRotationClassificationField( -1 ),
107 mScaleClassificationField( -1 ),
171 return mPen.widthF();
200 mBrush.setTextureImage( QImage( path ) );
208 if ( name.startsWith(
"svg:" ) )
211 QString myTempName = name;
212 myTempName.replace(
"svg:",
"" );
213 QFile myFile( myTempName );
214 if ( !myFile.exists() )
216 QgsDebugMsg(
"\n\n\n *** Svg Symbol not found on fs ***" );
222 for (
int i = 0; i < svgPaths.size(); i++ )
225 QFileInfo myInfo( myTempName );
226 QString myFileName = myInfo.fileName();
227 QString myLowestDir = myInfo.dir().dirName();
228 QString myLocalPath = svgPaths[i] +
"/" + myLowestDir +
"/" + myFileName;
230 QgsDebugMsg(
"Alternative svg path: " + myLocalPath );
231 if ( QFile( myLocalPath ).exists() )
233 name =
"svg:" + myLocalPath;
236 else if ( myInfo.isRelative() )
239 if ( pfi.exists() && QFile( pfi.canonicalPath() + QDir::separator() + myTempName ).exists() )
241 name =
"svg:" + pfi.canonicalPath() + QDir::separator() + myTempName;
253 QgsDebugMsg(
"Computed alternate path but no svg there either" );
300 QImage img( 15, 15, QImage::Format_ARGB32 );
302 img.fill( QColor( 255, 255, 255, 0 ).rgba() );
304 p.setRenderHints( QPainter::Antialiasing );
309 myPath.moveTo( 0, 0 );
310 myPath.cubicTo( 15, 0, 5, 7, 15, 15 );
311 p.drawPath( myPath );
320 QImage img( 15, 15, QImage::Format_ARGB32 );
322 img.fill( QColor( 255, 255, 255, 0 ).rgba() );
324 p.setRenderHints( QPainter::Antialiasing );
330 myPolygon << QPoint( 2, 2 )
351 p.drawPolygon( myPolygon );
363 cache2( widthScale, selectionColor, opacity );
383 double rotation,
double rasterScaleFactor,
double opacity )
385 double scaleProduct = scale * rasterScaleFactor;
388 if ( scaleProduct > 0.9 && scaleProduct < 1.1 && 0 == rotation )
397 QImage preRotateImage;
399 double newWidth =
mPen.widthF() * widthScale * rasterScaleFactor;
400 pen.setWidthF( newWidth );
404 pen.setColor( selectionColor );
408 (
float )(
mSize * scale * widthScale * rasterScaleFactor ),
413 QgsDebugMsgLevel( QString(
"marker:%1 mPointSize:%2 mPointSizeUnits:%3 scale:%4 widthScale:%5 rasterScaleFactor:%6 opacity:%7" )
415 .arg( scale ).arg( widthScale ).arg( rasterScaleFactor ).arg( opacity ), 3 );
420 (
float )(
mSize * scale * widthScale * rasterScaleFactor ),
424 QMatrix rotationMatrix;
425 rotationMatrix = rotationMatrix.rotate( rotation );
427 return preRotateImage.transformed( rotationMatrix, Qt::SmoothTransformation );
434 pen.setColor( selectionColor );
456 pen.setWidthF( widthScale * pen.widthF() );
462 brush.setColor( selectionColor );
463 pen.setColor( selectionColor );
484 QDomElement node = document.createElement( name );
485 QDomText txt = document.createTextNode( value );
486 if ( value.isNull() )
488 node.setAttribute(
"null",
"1" );
490 symbol.appendChild( node );
491 node.appendChild( txt );
496 bool returnval =
false;
498 QDomElement symbol = document.createElement(
"symbol" );
499 item.appendChild( symbol );
506 if ( name.startsWith(
"svg:" ) )
508 name = name.mid( 4 );
510 QFileInfo fi( name );
513 name = fi.canonicalFilePath();
517 for (
int i = 0; i < svgPaths.size(); i++ )
519 QString dir = QFileInfo( svgPaths[i] ).canonicalFilePath();
521 if ( !dir.isEmpty() && name.startsWith( dir ) )
523 name = name.mid( dir.size() );
529 name =
"svg:" + name;
532 appendText( symbol, document,
"pointsymbol", name );
543 QDomElement outlinecolor = document.createElement(
"outlinecolor" );
544 outlinecolor.setAttribute(
"red", QString::number(
mPen.color().red() ) );
545 outlinecolor.setAttribute(
"green", QString::number(
mPen.color().green() ) );
546 outlinecolor.setAttribute(
"blue", QString::number(
mPen.color().blue() ) );
547 symbol.appendChild( outlinecolor );
550 appendText( symbol, document,
"outlinewidth", QString::number(
mPen.widthF() ) );
552 QDomElement fillcolor = document.createElement(
"fillcolor" );
553 fillcolor.setAttribute(
"red", QString::number(
mBrush.color().red() ) );
554 fillcolor.setAttribute(
"green", QString::number(
mBrush.color().green() ) );
555 fillcolor.setAttribute(
"blue", QString::number(
mBrush.color().blue() ) );
556 symbol.appendChild( fillcolor );
566 QDomNode node = synode.namedItem( name +
"name" );
568 if ( !node.isNull() )
571 QString name = node.toElement().text();
573 for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); it++ )
574 if ( it->name() == name )
580 node = synode.namedItem( name );
582 return node.isNull() ? -1 : node.toElement().text().toInt();
591 QDomNode lvalnode = synode.namedItem(
"lowervalue" );
592 if ( ! lvalnode.isNull() )
594 QDomElement lvalelement = lvalnode.toElement();
595 if ( lvalelement.attribute(
"null" ).toInt() == 1 )
605 QDomNode uvalnode = synode.namedItem(
"uppervalue" );
606 if ( ! uvalnode.isNull() )
608 QDomElement uvalelement = uvalnode.toElement();
612 QDomNode labelnode = synode.namedItem(
"label" );
613 if ( ! labelnode.isNull() )
615 QDomElement labelelement = labelnode.toElement();
616 mLabel = labelelement.text();
619 QDomNode psymbnode = synode.namedItem(
"pointsymbol" );
621 if ( ! psymbnode.isNull() )
623 QDomElement psymbelement = psymbnode.toElement();
627 QDomNode psizenode = synode.namedItem(
"pointsize" );
629 if ( ! psizenode.isNull() )
631 QDomElement psizeelement = psizenode.toElement();
635 QDomNode psizeunitnodes = synode.namedItem(
"pointsizeunits" );
636 if ( ! psizeunitnodes.isNull() )
638 QDomElement psizeunitelement = psizeunitnodes.toElement();
639 QgsDebugMsg( QString(
"psizeunitelement:%1" ).arg( psizeunitelement.text() ) );
640 setPointSizeUnits( psizeunitelement.text().compare(
"mapunits", Qt::CaseInsensitive ) == 0 );
655 QDomNode outlcnode = synode.namedItem(
"outlinecolor" );
656 QDomElement oulcelement = outlcnode.toElement();
657 int red = oulcelement.attribute(
"red" ).toInt();
658 int green = oulcelement.attribute(
"green" ).toInt();
659 int blue = oulcelement.attribute(
"blue" ).toInt();
660 setColor( QColor( red, green, blue ) );
662 QDomNode outlstnode = synode.namedItem(
"outlinestyle" );
663 QDomElement outlstelement = outlstnode.toElement();
666 QDomNode outlwnode = synode.namedItem(
"outlinewidth" );
667 QDomElement outlwelement = outlwnode.toElement();
670 QDomNode fillcnode = synode.namedItem(
"fillcolor" );
671 QDomElement fillcelement = fillcnode.toElement();
672 red = fillcelement.attribute(
"red" ).toInt();
673 green = fillcelement.attribute(
"green" ).toInt();
674 blue = fillcelement.attribute(
"blue" ).toInt();
677 QDomNode texturepathnode = synode.namedItem(
"texturepath" );
678 QDomElement texturepathelement = texturepathnode.toElement();
682 QDomNode fillpnode = synode.namedItem(
"fillpattern" );
683 QDomElement fillpelement = fillpnode.toElement();