Quantum GIS API Documentation  1.8
src/core/symbology-ng/qgssymbollayerv2utils.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     qgssymbollayerv2utils.h
00003     ---------------------
00004     begin                : November 2009
00005     copyright            : (C) 2009 by Martin Dobias
00006     email                : wonder.sk at gmail.com
00007  ***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  ***************************************************************************/
00015 
00016 
00017 #ifndef QGSSYMBOLLAYERV2UTILS_H
00018 #define QGSSYMBOLLAYERV2UTILS_H
00019 
00020 #include <QMap>
00021 #include <Qt>
00022 #include <QtCore>
00023 #include <QFont>
00024 #include <QColor>
00025 #include "qgssymbolv2.h"
00026 #include "qgis.h"
00027 
00028 class QgsSymbolLayerV2;
00029 class QgsVectorColorRampV2;
00030 
00031 typedef QMap<QString, QString> QgsStringMap;
00032 typedef QMap<QString, QgsSymbolV2* > QgsSymbolV2Map;
00033 
00034 class QDomDocument;
00035 class QDomElement;
00036 class QIcon;
00037 class QPixmap;
00038 class QPointF;
00039 class QSize;
00040 
00041 class CORE_EXPORT QgsSymbolLayerV2Utils
00042 {
00043   public:
00044 
00045     static QString encodeColor( QColor color );
00046     static QColor decodeColor( QString str );
00047 
00048     static QString encodeSldAlpha( int alpha );
00049     static int decodeSldAlpha( QString str );
00050 
00051     static QString encodeSldFontStyle( QFont::Style style );
00052     static QFont::Style decodeSldFontStyle( QString str );
00053 
00054     static QString encodeSldFontWeight( int weight );
00055     static int decodeSldFontWeight( QString str );
00056 
00057     static QString encodePenStyle( Qt::PenStyle style );
00058     static Qt::PenStyle decodePenStyle( QString str );
00059 
00060     static QString encodePenJoinStyle( Qt::PenJoinStyle style );
00061     static Qt::PenJoinStyle decodePenJoinStyle( QString str );
00062 
00063     static QString encodePenCapStyle( Qt::PenCapStyle style );
00064     static Qt::PenCapStyle decodePenCapStyle( QString str );
00065 
00066     static QString encodeSldLineJoinStyle( Qt::PenJoinStyle style );
00067     static Qt::PenJoinStyle decodeSldLineJoinStyle( QString str );
00068 
00069     static QString encodeSldLineCapStyle( Qt::PenCapStyle style );
00070     static Qt::PenCapStyle decodeSldLineCapStyle( QString str );
00071 
00072     static QString encodeBrushStyle( Qt::BrushStyle style );
00073     static Qt::BrushStyle decodeBrushStyle( QString str );
00074 
00075     static QString encodeSldBrushStyle( Qt::BrushStyle style );
00076     static Qt::BrushStyle decodeSldBrushStyle( QString str );
00077 
00078     static QString encodePoint( QPointF point );
00079     static QPointF decodePoint( QString str );
00080 
00081     static QString encodeRealVector( const QVector<qreal>& v );
00082     static QVector<qreal> decodeRealVector( const QString& s );
00083 
00084     static QString encodeSldRealVector( const QVector<qreal>& v );
00085     static QVector<qreal> decodeSldRealVector( const QString& s );
00086 
00087     static QString encodeOutputUnit( QgsSymbolV2::OutputUnit unit );
00088     static QgsSymbolV2::OutputUnit decodeOutputUnit( QString str );
00089 
00090     static QString encodeSldUom( QgsSymbolV2::OutputUnit unit, double *scaleFactor );
00091     static QgsSymbolV2::OutputUnit decodeSldUom( QString str, double *scaleFactor );
00092 
00093     static QIcon symbolPreviewIcon( QgsSymbolV2* symbol, QSize size );
00094     static QIcon symbolLayerPreviewIcon( QgsSymbolLayerV2* layer, QgsSymbolV2::OutputUnit u, QSize size );
00095     static QIcon colorRampPreviewIcon( QgsVectorColorRampV2* ramp, QSize size );
00096 
00097     static QPixmap symbolPreviewPixmap( QgsSymbolV2* symbol, QSize size );
00098     static QPixmap colorRampPreviewPixmap( QgsVectorColorRampV2* ramp, QSize size );
00099 
00100     static QgsSymbolV2* loadSymbol( QDomElement& element );
00101     static QgsSymbolLayerV2* loadSymbolLayer( QDomElement& element );
00102     static QDomElement saveSymbol( QString name, QgsSymbolV2* symbol, QDomDocument& doc, QgsSymbolV2Map* subSymbols = NULL );
00103 
00104     static bool createSymbolLayerV2ListFromSld( QDomElement& element, QGis::GeometryType geomType, QgsSymbolLayerV2List &layers );
00105 
00106     static QgsSymbolLayerV2* createFillLayerFromSld( QDomElement &element );
00107     static QgsSymbolLayerV2* createLineLayerFromSld( QDomElement &element );
00108     static QgsSymbolLayerV2* createMarkerLayerFromSld( QDomElement &element );
00109 
00110     static bool convertPolygonSymbolizerToPointMarker( QDomElement &element, QgsSymbolLayerV2List &layerList );
00111     static bool hasExternalGraphic( QDomElement &element );
00112     static bool hasWellKnownMark( QDomElement &element );
00113 
00114     static bool needFontMarker( QDomElement &element );
00115     static bool needSvgMarker( QDomElement &element );
00116     static bool needEllipseMarker( QDomElement &element );
00117     static bool needMarkerLine( QDomElement &element );
00118     static bool needLinePatternFill( QDomElement &element );
00119     static bool needPointPatternFill( QDomElement &element );
00120     static bool needSvgFill( QDomElement &element );
00121 
00122     static void fillToSld( QDomDocument &doc, QDomElement &element,
00123                            Qt::BrushStyle brushStyle, QColor color = QColor() );
00124     static bool fillFromSld( QDomElement &element,
00125                              Qt::BrushStyle &brushStyle, QColor &color );
00126 
00127     static void lineToSld( QDomDocument &doc, QDomElement &element,
00128                            Qt::PenStyle penStyle, QColor color, double width = -1,
00129                            const Qt::PenJoinStyle *penJoinStyle = 0, const Qt::PenCapStyle *penCapStyle = 0,
00130                            const QVector<qreal> *customDashPattern = 0, double dashOffset = 0.0 );
00131     static bool lineFromSld( QDomElement &element,
00132                              Qt::PenStyle &penStyle, QColor &color, double &width,
00133                              Qt::PenJoinStyle *penJoinStyle = 0, Qt::PenCapStyle *penCapStyle = 0,
00134                              QVector<qreal> *customDashPattern = 0, double *dashOffset = 0 );
00135 
00136     static void externalGraphicToSld( QDomDocument &doc, QDomElement &element,
00137                                       QString path, QString mime,
00138                                       QColor color, double size = -1 );
00139     static bool externalGraphicFromSld( QDomElement &element,
00140                                         QString &path, QString &mime,
00141                                         QColor &color, double &size );
00142 
00143     static void wellKnownMarkerToSld( QDomDocument &doc, QDomElement &element,
00144                                       QString name, QColor color, QColor borderColor = QColor(),
00145                                       double borderWidth = -1, double size = -1 );
00146     static bool wellKnownMarkerFromSld( QDomElement &element,
00147                                         QString &name, QColor &color, QColor &borderColor,
00148                                         double &borderWidth, double &size );
00149 
00150     static void externalMarkerToSld( QDomDocument &doc, QDomElement &element,
00151                                      QString path, QString format, int *markIndex = 0,
00152                                      QColor color = QColor(), double size = -1 );
00153     static bool externalMarkerFromSld( QDomElement &element,
00154                                        QString &path, QString &format, int &markIndex,
00155                                        QColor &color, double &size );
00156 
00157 
00158     static void labelTextToSld( QDomDocument &doc, QDomElement &element, QString label,
00159                                 QFont font, QColor color = QColor(), double size = -1 );
00160 
00161     static void createRotationElement( QDomDocument &doc, QDomElement &element, QString rotationFunc );
00162     static bool rotationFromSldElement( QDomElement &element, QString &rotationFunc );
00163 
00164     static void createOpacityElement( QDomDocument &doc, QDomElement &element, QString alphaFunc );
00165     static bool opacityFromSldElement( QDomElement &element, QString &alphaFunc );
00166 
00167     static void createDisplacementElement( QDomDocument &doc, QDomElement &element, QPointF offset );
00168     static bool displacementFromSldElement( QDomElement &element, QPointF &offset );
00169 
00170     static void createOnlineResourceElement( QDomDocument &doc, QDomElement &element, QString path, QString format );
00171     static bool onlineResourceFromSldElement( QDomElement &element, QString &path, QString &format );
00172 
00173     static void createGeometryElement( QDomDocument &doc, QDomElement &element, QString geomFunc );
00174     static bool geometryFromSldElement( QDomElement &element, QString &geomFunc );
00175 
00176     static bool createFunctionElement( QDomDocument &doc, QDomElement &element, QString function );
00177     static bool functionFromSldElement( QDomElement &element, QString &function );
00178 
00179     static QDomElement createSvgParameterElement( QDomDocument &doc, QString name, QString value );
00180     static QgsStringMap getSvgParameterList( QDomElement &element );
00181 
00182     static QDomElement createVendorOptionElement( QDomDocument &doc, QString name, QString value );
00183     static QgsStringMap getVendorOptionList( QDomElement &element );
00184 
00185     static QgsStringMap parseProperties( QDomElement& element );
00186     static void saveProperties( QgsStringMap props, QDomDocument& doc, QDomElement& element );
00187 
00188     static QgsSymbolV2Map loadSymbols( QDomElement& element );
00189     static QDomElement saveSymbols( QgsSymbolV2Map& symbols, QString tagName, QDomDocument& doc );
00190 
00191     static void clearSymbolMap( QgsSymbolV2Map& symbols );
00192 
00193     static QgsVectorColorRampV2* loadColorRamp( QDomElement& element );
00194     static QDomElement saveColorRamp( QString name, QgsVectorColorRampV2* ramp, QDomDocument& doc );
00195 
00197     static double lineWidthScaleFactor( QgsRenderContext& c, QgsSymbolV2::OutputUnit u );
00199     static double pixelSizeScaleFactor( QgsRenderContext& c, QgsSymbolV2::OutputUnit u );
00201     static QgsRenderContext createRenderContext( QPainter* p );
00202 
00204     static void multiplyImageOpacity( QImage* image, qreal alpha );
00205 
00207     static void sortVariantList( QList<QVariant>& list, Qt::SortOrder order );
00209     static QPointF pointOnLineWithDistance( const QPointF& startPoint, const QPointF& directionPoint, double distance );
00210 };
00211 
00212 class QPolygonF;
00213 
00215 QPolygonF offsetLine( QPolygonF polyline, double dist );
00216 
00217 
00218 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines