📄 qgssymbol.cpp
字号:
if ( selected ) { return mPointSymbolImageSelected; } else { return mPointSymbolImage; }}QImage QgsSymbol::getPointSymbolAsImage( double widthScale, bool selected, QColor selectionColor, double scale, double rotation ){ //QgsDebugMsg(QString("Symbol scale = %1, and rotation = %2").arg(scale).arg(rotation)); if ( 1.0 == scale && 0 == rotation ) { // If scale is 1.0 and rotation 0.0, use cached image. return getCachedPointSymbolAsImage( widthScale, selected, selectionColor ); } QImage preRotateImage; if ( selected ) { QPen pen = mPen; pen.setColor ( selectionColor ); QBrush brush = mBrush; preRotateImage = QgsMarkerCatalogue::instance()->imageMarker ( mPointSymbolName, (int)(mPointSize * scale), pen, mBrush ); } else { preRotateImage = QgsMarkerCatalogue::instance()->imageMarker ( mPointSymbolName, (int)(mPointSize * scale), mPen, mBrush ); } QMatrix rotationMatrix; rotationMatrix = rotationMatrix.rotate(rotation); return preRotateImage.transformed(rotationMatrix, Qt::SmoothTransformation);}void QgsSymbol::cache( QColor selectionColor ){ QPen pen = mPen; pen.setColor ( selectionColor ); QBrush brush = mBrush; // For symbols that have a different coloured border, the line // below causes the fill colour to be wrong for the print // composer. Not sure why... // brush.setColor ( selectionColor ); mPointSymbolImage = QgsMarkerCatalogue::instance()->imageMarker ( mPointSymbolName, mPointSize, mPen, mBrush ); mPointSymbolImageSelected = QgsMarkerCatalogue::instance()->imageMarker ( mPointSymbolName, mPointSize, pen, brush ); mSelectionColor = selectionColor; mCacheUpToDate = true;}void QgsSymbol::cache2( double widthScale, QColor selectionColor ){ //std::cerr << "QgsSymbol::cache2 widthScale = " << widthScale << std::endl; QPen pen = mPen; pen.setWidth ( (int) ( widthScale * pen.width() ) ); mPointSymbolImage2 = QgsMarkerCatalogue::instance()->imageMarker ( mPointSymbolName, mPointSize, pen, mBrush, false ); QBrush brush = mBrush; brush.setColor ( selectionColor ); pen.setColor ( selectionColor ); mPointSymbolImageSelected2 = QgsMarkerCatalogue::instance()->imageMarker ( mPointSymbolName, mPointSize, pen, brush, false ); mSelectionColor2 = selectionColor; mWidthScale = widthScale; mCacheUpToDate2 = true;}bool QgsSymbol::writeXML( QDomNode & item, QDomDocument & document ) const{ bool returnval = false; returnval = true; // no error checking yet QDomElement symbol=document.createElement("symbol"); item.appendChild(symbol); QDomElement lowervalue=document.createElement("lowervalue"); QDomText lowervaluetxt=document.createTextNode(mLowerValue); symbol.appendChild(lowervalue); lowervalue.appendChild(lowervaluetxt); QDomElement uppervalue=document.createElement("uppervalue"); QDomText uppervaluetxt=document.createTextNode(mUpperValue); symbol.appendChild(uppervalue); uppervalue.appendChild(uppervaluetxt); QDomElement label=document.createElement("label"); QDomText labeltxt=document.createTextNode(mLabel); symbol.appendChild(label); label.appendChild(labeltxt); QDomElement pointsymbol=document.createElement("pointsymbol"); QDomText pointsymboltxt=document.createTextNode(pointSymbolName()); symbol.appendChild(pointsymbol); pointsymbol.appendChild(pointsymboltxt); QDomElement pointsize=document.createElement("pointsize"); QDomText pointsizetxt=document.createTextNode( QString::number(pointSize()) ); symbol.appendChild(pointsize); pointsize.appendChild(pointsizetxt); QDomElement rotationclassificationfield=document.createElement("rotationclassificationfield"); QDomText rotationclassificationfieldtxt=document.createTextNode(QString::number(mRotationClassificationField)); rotationclassificationfield.appendChild(rotationclassificationfieldtxt); symbol.appendChild(rotationclassificationfield); QDomElement scaleclassificationfield=document.createElement("scaleclassificationfield"); QDomText scaleclassificationfieldtxt=document.createTextNode(QString::number(mScaleClassificationField)); scaleclassificationfield.appendChild(scaleclassificationfieldtxt); symbol.appendChild(scaleclassificationfield); QDomElement outlinecolor=document.createElement("outlinecolor"); outlinecolor.setAttribute("red",QString::number(mPen.color().red())); outlinecolor.setAttribute("green",QString::number(mPen.color().green())); outlinecolor.setAttribute("blue",QString::number(mPen.color().blue())); symbol.appendChild(outlinecolor); QDomElement outlinestyle=document.createElement("outlinestyle"); QDomText outlinestyletxt=document.createTextNode(QgsSymbologyUtils::penStyle2QString(mPen.style())); outlinestyle.appendChild(outlinestyletxt); symbol.appendChild(outlinestyle); QDomElement outlinewidth=document.createElement("outlinewidth"); QDomText outlinewidthtxt=document.createTextNode(QString::number(mPen.width())); outlinewidth.appendChild(outlinewidthtxt); symbol.appendChild(outlinewidth); QDomElement fillcolor=document.createElement("fillcolor"); fillcolor.setAttribute("red",QString::number(mBrush.color().red())); fillcolor.setAttribute("green",QString::number(mBrush.color().green())); fillcolor.setAttribute("blue",QString::number(mBrush.color().blue())); symbol.appendChild(fillcolor); QDomElement fillpattern=document.createElement("fillpattern"); QDomText fillpatterntxt=document.createTextNode(QgsSymbologyUtils::brushStyle2QString(mBrush.style())); fillpattern.appendChild(fillpatterntxt); symbol.appendChild(fillpattern); fillpattern.appendChild(fillpatterntxt); QDomElement texturepath=document.createElement("texturepath"); QDomText texturepathtxt=document.createTextNode(mTextureFilePath); symbol.appendChild(texturepath); texturepath.appendChild(texturepathtxt); return returnval;}bool QgsSymbol::readXML( QDomNode & synode ){ // Legacy project file formats didn't have support for pointsymbol nor // pointsize DOM elements. Therefore we should check whether these // actually exist. QDomNode lvalnode = synode.namedItem("lowervalue"); if( ! lvalnode.isNull() ) { QDomElement lvalelement = lvalnode.toElement(); mLowerValue=lvalelement.text(); } QDomNode uvalnode = synode.namedItem("uppervalue"); if( ! uvalnode.isNull() ) { QDomElement uvalelement = uvalnode.toElement(); mUpperValue=uvalelement.text(); } QDomNode labelnode = synode.namedItem("label"); if( ! labelnode.isNull() ) { QDomElement labelelement = labelnode.toElement(); mLabel=labelelement.text(); } QDomNode psymbnode = synode.namedItem("pointsymbol"); if ( ! psymbnode.isNull() ) { QDomElement psymbelement = psymbnode.toElement(); setNamedPointSymbol( psymbelement.text() ); } QDomNode psizenode = synode.namedItem("pointsize"); if ( ! psizenode.isNull() ) { QDomElement psizeelement = psizenode.toElement(); setPointSize( psizeelement.text().toInt() ); } mRotationClassificationField = -1; mScaleClassificationField = -1; QDomNode classnode = synode.namedItem("rotationclassificationfield"); if ( !classnode.isNull() ) { mRotationClassificationField = classnode.toElement().text().toInt(); QgsDebugMsg("Found rotationfield: " + QString::number(rotationClassificationField())); } classnode = synode.namedItem("scaleclassificationfield"); if ( !classnode.isNull() ) { mScaleClassificationField = classnode.toElement().text().toInt(); QgsDebugMsg("Found scalefield: " + QString::number(scaleClassificationField())); } QDomNode outlcnode = synode.namedItem("outlinecolor"); QDomElement oulcelement = outlcnode.toElement(); int red = oulcelement.attribute("red").toInt(); int green = oulcelement.attribute("green").toInt(); int blue = oulcelement.attribute("blue").toInt(); setColor(QColor(red, green, blue)); QDomNode outlstnode = synode.namedItem("outlinestyle"); QDomElement outlstelement = outlstnode.toElement(); setLineStyle(QgsSymbologyUtils::qString2PenStyle(outlstelement.text())); QDomNode outlwnode = synode.namedItem("outlinewidth"); QDomElement outlwelement = outlwnode.toElement(); setLineWidth(outlwelement.text().toInt()); QDomNode fillcnode = synode.namedItem("fillcolor"); QDomElement fillcelement = fillcnode.toElement(); red = fillcelement.attribute("red").toInt(); green = fillcelement.attribute("green").toInt(); blue = fillcelement.attribute("blue").toInt(); setFillColor(QColor(red, green, blue)); QDomNode texturepathnode = synode.namedItem("texturepath"); QDomElement texturepathelement = texturepathnode.toElement(); setCustomTexture(texturepathelement.text()); //run this after setting the custom texture path, so we override the brush if it isn't the custom pattern brush. QDomNode fillpnode = synode.namedItem("fillpattern"); QDomElement fillpelement = fillpnode.toElement(); setFillStyle(QgsSymbologyUtils::qString2BrushStyle(fillpelement.text())); return true;}int QgsSymbol::rotationClassificationField() const{ return mRotationClassificationField;}void QgsSymbol::setRotationClassificationField(int field){ mRotationClassificationField = field;}int QgsSymbol::scaleClassificationField() const{ return mScaleClassificationField;}void QgsSymbol::setScaleClassificationField(int field){ mScaleClassificationField = field;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -