Quantum GIS API Documentation
1.8
|
00001 /*************************************************************************** 00002 qgscomposerlegend.h - description 00003 ------------------- 00004 begin : June 2008 00005 copyright : (C) 2008 by Marco Hugentobler 00006 email : marco dot hugentobler at karto dot baug dot ethz dot ch 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef QGSCOMPOSERLEGEND_H 00019 #define QGSCOMPOSERLEGEND_H 00020 00021 #include "qgscomposeritem.h" 00022 #include "qgslegendmodel.h" 00023 00024 class QgsSymbol; 00025 class QgsSymbolV2; 00026 class QgsComposerGroupItem; 00027 class QgsComposerLayerItem; 00028 class QgsComposerMap; 00029 00033 class CORE_EXPORT QgsComposerLegend: public QgsComposerItem 00034 { 00035 Q_OBJECT 00036 00037 public: 00038 QgsComposerLegend( QgsComposition* composition ); 00039 ~QgsComposerLegend(); 00040 00042 virtual int type() const { return ComposerLegend; } 00043 00045 void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ); 00046 00048 QSizeF paintAndDetermineSize( QPainter* painter ); 00049 00051 void adjustBoxSize(); 00052 00054 QgsLegendModel* model() {return &mLegendModel;} 00055 00056 //setters and getters 00057 void setTitle( const QString& t ) {mTitle = t;} 00058 QString title() const {return mTitle;} 00059 00060 QFont titleFont() const; 00061 void setTitleFont( const QFont& f ); 00062 00063 QFont groupFont() const; 00064 void setGroupFont( const QFont& f ); 00065 00066 QFont layerFont() const; 00067 void setLayerFont( const QFont& f ); 00068 00069 QFont itemFont() const; 00070 void setItemFont( const QFont& f ); 00071 00072 double boxSpace() const {return mBoxSpace;} 00073 void setBoxSpace( double s ) {mBoxSpace = s;} 00074 00075 double groupSpace() const {return mGroupSpace;} 00076 void setGroupSpace( double s ) {mGroupSpace = s;} 00077 00078 double layerSpace() const {return mLayerSpace;} 00079 void setLayerSpace( double s ) {mLayerSpace = s;} 00080 00081 double symbolSpace() const {return mSymbolSpace;} 00082 void setSymbolSpace( double s ) {mSymbolSpace = s;} 00083 00084 double iconLabelSpace() const {return mIconLabelSpace;} 00085 void setIconLabelSpace( double s ) {mIconLabelSpace = s;} 00086 00087 double symbolWidth() const {return mSymbolWidth;} 00088 void setSymbolWidth( double w ) {mSymbolWidth = w;} 00089 00090 double symbolHeight() const {return mSymbolHeight;} 00091 void setSymbolHeight( double h ) {mSymbolHeight = h;} 00092 00093 void setWrapChar( const QString& t ) {mWrapChar = t;} 00094 QString wrapChar() const {return mWrapChar;} 00095 00096 void setComposerMap( const QgsComposerMap* map ); 00097 const QgsComposerMap* composerMap() const { return mComposerMap; } 00098 00100 void updateLegend(); 00101 00106 bool writeXML( QDomElement& elem, QDomDocument & doc ) const; 00107 00112 bool readXML( const QDomElement& itemElem, const QDomDocument& doc ); 00113 00114 public slots: 00116 void synchronizeWithModel(); 00118 void invalidateCurrentMap(); 00119 00120 protected: 00121 QString mTitle; 00122 QString mWrapChar; 00123 00124 //different fonts for entries 00125 QFont mTitleFont; 00126 QFont mGroupFont; 00127 QFont mLayerFont; 00128 QFont mItemFont; 00129 00131 double mBoxSpace; 00133 double mGroupSpace; 00135 double mLayerSpace; 00137 double mSymbolSpace; 00139 double mIconLabelSpace; 00141 double mSymbolWidth; 00143 double mSymbolHeight; 00144 00146 double mlineSpacing; 00147 00148 QgsLegendModel mLegendModel; 00149 00151 const QgsComposerMap* mComposerMap; 00152 00153 00154 private: 00155 QgsComposerLegend(); //forbidden 00156 00158 void drawGroupItem( QPainter* p, QgsComposerGroupItem* groupItem, double& currentYCoord, double& maxXCoord ); 00160 void drawLayerItem( QPainter* p, QgsComposerLayerItem* layerItem, double& currentYCoord, double& maxXCoord ); 00161 00169 void drawLayerChildItems( QPainter* p, QStandardItem* layerItem, double& currentYCoord, double& maxXCoord, int layerOpacity = 255 ); 00170 00173 void drawSymbol( QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition, double& symbolHeight, int layerOpacity = 255 ) const; 00174 void drawSymbolV2( QPainter* p, QgsSymbolV2* s, double currentYCoord, double& currentXPosition, double& symbolHeight, int layerOpacity = 255 ) const; 00175 void drawPointSymbol( QPainter*, QgsSymbol* s, double currentYCoord, double& currentXPosition, double& symbolHeight, int opacity = 255 ) const; 00176 void drawLineSymbol( QPainter*, QgsSymbol* s, double currentYCoord, double& currentXPosition, int opacity = 255 ) const; 00177 void drawPolygonSymbol( QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition, int opacity = 255 ) const; 00178 00180 QStringList layerIdList() const; 00181 00182 private: 00185 QStringList splitStringForWrapping( QString stringToSplt ); 00186 }; 00187 00188 #endif