⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qgssymbol.cpp

📁 一个非常好的GIS开源新版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************                          QgsSymbol.cpp  -  description                             -------------------    begin                : Sun Aug 11 2002    copyright            : (C) 2002 by Gary E.Sherman    email                : sherman at mrcc dot com       Romans 3:23=>Romans 6:23=>Romans 5:8=>Romans 10:9,10=>Romans 12 ***************************************************************************//*************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * ***************************************************************************//* $Id: qgssymbol.cpp 8089 2008-01-29 13:32:36Z timlinux $ */#include <cmath>#include <iostream>#include "qgssymbol.h"#include "qgslogger.h"#include "qgssymbologyutils.h"#include "qgsmarkercatalogue.h"#include "qgsapplication.h"#include <QPainter>#include <QDomNode>#include <QDomDocument>#include <QImage>#include <QDir>#include <QFileInfo>//#include <QString>//do we have to include qstring?QgsSymbol::QgsSymbol(QGis::VectorType t, QString lvalue, QString uvalue, QString label) :       mLowerValue(lvalue),      mUpperValue(uvalue),      mLabel(label),      mType(t),      mPointSymbolName( "hard:circle" ),      mPointSize( 10 ),      mPointSymbolImage(1,1, QImage::Format_ARGB32_Premultiplied),      mWidthScale(1.0),      mCacheUpToDate( false ),      mCacheUpToDate2( false ),      mRotationClassificationField(-1),      mScaleClassificationField(-1){}QgsSymbol::QgsSymbol(QGis::VectorType t, QString lvalue, QString uvalue, QString label, QColor c) :       mLowerValue(lvalue),      mUpperValue(uvalue),      mLabel(label),      mType(t),      mPen( c ),      mBrush( c ),      mPointSymbolName( "hard:circle" ),      mPointSize( 6 ),      mPointSymbolImage(1,1, QImage::Format_ARGB32_Premultiplied),      mWidthScale(1.0),      mCacheUpToDate( false ),      mCacheUpToDate2( false ),      mRotationClassificationField(-1),      mScaleClassificationField(-1){}QgsSymbol::QgsSymbol()    : mPointSymbolName( "hard:circle" ),      mPointSize( 6 ),      mPointSymbolImage(1,1, QImage::Format_ARGB32_Premultiplied),      mWidthScale(1.0),      mCacheUpToDate( false ),      mCacheUpToDate2( false ),      mRotationClassificationField(-1),      mScaleClassificationField(-1){}QgsSymbol::QgsSymbol(QColor c)    : mPen( c ),      mBrush( c ),      mPointSymbolName( "hard:circle" ),      mPointSize( 6 ),      mPointSymbolImage(1,1, QImage::Format_ARGB32_Premultiplied),      mWidthScale(1.0),      mCacheUpToDate( false ),      mCacheUpToDate2( false ),      mRotationClassificationField(-1),      mScaleClassificationField(-1){}QgsSymbol::QgsSymbol(const QgsSymbol& s){  if (this != &s)  {    mLowerValue = s.mLowerValue;    mUpperValue = s.mUpperValue;    mLabel = s.mLabel;    mType = s.mType;    mPen = s.mPen;    mBrush = s.mBrush;    mTextureFilePath = s.mTextureFilePath;    mPointSymbolName = s.mPointSymbolName;    mPointSize = s.mPointSize;    mPointSymbolImage = s.mPointSymbolImage;    mPointSymbolImageSelected = s.mPointSymbolImageSelected;    mWidthScale = s.mWidthScale;    mPointSymbolImage2 = s.mPointSymbolImage2;    mPointSymbolImageSelected2 = s.mPointSymbolImageSelected2;    mCacheUpToDate = s.mCacheUpToDate;    mCacheUpToDate2 = s.mCacheUpToDate2;    mSelectionColor = s.mSelectionColor;    mSelectionColor2 = s.mSelectionColor2;    mRotationClassificationField = s.mRotationClassificationField;    mScaleClassificationField = s.mScaleClassificationField;  }}QgsSymbol::~QgsSymbol(){}QColor QgsSymbol::color() const{  return mPen.color();}void QgsSymbol::setColor(QColor c){  mPen.setColor(c);  mCacheUpToDate = mCacheUpToDate2 = false;}QColor QgsSymbol::fillColor() const{  return mBrush.color();}void QgsSymbol::setFillColor(QColor c){  mBrush.setColor(c);  mCacheUpToDate = mCacheUpToDate2 = false;}int QgsSymbol::lineWidth() const{  return mPen.width();}void QgsSymbol::setLineWidth(int w){  mPen.setWidth(w);  mCacheUpToDate = mCacheUpToDate2 = false;}void QgsSymbol::setLineStyle( Qt::PenStyle s ){  mPen.setStyle(s);  mCacheUpToDate = mCacheUpToDate2 = false;}void QgsSymbol::setFillStyle( Qt::BrushStyle s ){  mBrush.setStyle(s);  mCacheUpToDate = mCacheUpToDate2 = false;}QString QgsSymbol::customTexture() const{	return mTextureFilePath;}void QgsSymbol::setCustomTexture( QString path ){  mTextureFilePath = path;  mBrush.setTextureImage(QImage (path));  mCacheUpToDate = mCacheUpToDate2 = false;}//should we set the path independently of setting the texture?void QgsSymbol::setNamedPointSymbol(QString name){  // do some sanity checking for svgs...  QString myTempName = name;  myTempName.replace("svg:","");  QFile myFile(myTempName);  if (!myFile.exists())  {    QgsDebugMsg("\n\n\n *** Svg Symbol not found on fs ***")    QgsDebugMsg("Name: " + name);    //see if we can resolve the problem...    //by using the qgis svg dir from this local machine    //one day when user specified svg are allowed we need     //to adjust this logic probably...    QString svgPath = QgsApplication::svgPath();    QgsDebugMsg( "SvgPath: " + svgPath);    QFileInfo myInfo(myTempName);    QString myFileName = myInfo.fileName(); // foo.svg    QString myLowestDir = myInfo.dir().dirName();    QString myLocalPath = svgPath + QDir::separator() +      myLowestDir + QDir::separator() +      myFileName;    QgsDebugMsg("Alternative svg path: " + myLocalPath);    if (QFile(myLocalPath).exists())    {      name="svg:"+myLocalPath;      QgsDebugMsg("Svg found in alternative path");     }    else    {      //couldnt find the file, no happy ending :-(      QgsDebugMsg("Computed alternate path but no svg there either");    }  }  mPointSymbolName = name;  mCacheUpToDate = mCacheUpToDate2 = false;}QString QgsSymbol::pointSymbolName() const{    return mPointSymbolName;}void QgsSymbol::setPointSize(int s){    if ( s < 3 )  	mPointSize = 3;    else     	mPointSize = s;    mCacheUpToDate = mCacheUpToDate2 = false;}int QgsSymbol::pointSize() const{    return mPointSize;}QImage QgsSymbol::getLineSymbolAsImage(){    QImage img(15, 15, QImage::Format_ARGB32_Premultiplied);    img.fill(QColor(255,255,255,0).rgba());    QPainter p(&img);    p.setPen(mPen);    p.drawLine(0, 0, 15, 15);    return img; //this is ok because of qts sharing mechanism}QImage QgsSymbol::getPolygonSymbolAsImage(){   QImage img(15, 15, QImage::Format_ARGB32_Premultiplied);   img.fill(QColor(255,255,255,0).rgba());   QPainter p(&img);   p.setPen(mPen);   p.setBrush(mBrush);   p.drawRect(0, 0, 15, 15);   return img; //this is ok because of qts sharing mechanism }QImage QgsSymbol::getCachedPointSymbolAsImage(  double widthScale,               bool selected, QColor selectionColor ){  if ( !mCacheUpToDate        || ( selected && mSelectionColor != selectionColor ) )  {    if ( selected ) {      cache(  selectionColor );    } else {      cache(  mSelectionColor );    }  }  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -