Quantum GIS API Documentation
1.7.4
|
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 layerSpace() const {return mLayerSpace;} 00076 void setLayerSpace( double s ) {mLayerSpace = s;} 00077 00078 double symbolSpace() const {return mSymbolSpace;} 00079 void setSymbolSpace( double s ) {mSymbolSpace = s;} 00080 00081 double iconLabelSpace() const {return mIconLabelSpace;} 00082 void setIconLabelSpace( double s ) {mIconLabelSpace = s;} 00083 00084 double symbolWidth() const {return mSymbolWidth;} 00085 void setSymbolWidth( double w ) {mSymbolWidth = w;} 00086 00087 double symbolHeight() const {return mSymbolHeight;} 00088 void setSymbolHeight( double h ) {mSymbolHeight = h;} 00089 00090 void setComposerMap( const QgsComposerMap* map ); 00091 const QgsComposerMap* composerMap() const { return mComposerMap; } 00092 00094 void updateLegend(); 00095 00100 bool writeXML( QDomElement& elem, QDomDocument & doc ) const; 00101 00106 bool readXML( const QDomElement& itemElem, const QDomDocument& doc ); 00107 00108 public slots: 00110 void synchronizeWithModel(); 00112 void invalidateCurrentMap(); 00113 00114 protected: 00115 QString mTitle; 00116 00117 //different fonts for entries 00118 QFont mTitleFont; 00119 QFont mGroupFont; 00120 QFont mLayerFont; 00121 QFont mItemFont; 00122 00124 double mBoxSpace; 00126 double mLayerSpace; 00128 double mSymbolSpace; 00130 double mIconLabelSpace; 00132 double mSymbolWidth; 00134 double mSymbolHeight; 00135 00136 QgsLegendModel mLegendModel; 00137 00139 const QgsComposerMap* mComposerMap; 00140 00141 00142 private: 00143 QgsComposerLegend(); //forbidden 00144 00146 void drawGroupItem( QPainter* p, QgsComposerGroupItem* groupItem, double& currentYCoord, double& maxXCoord ); 00148 void drawLayerItem( QPainter* p, QgsComposerLayerItem* layerItem, double& currentYCoord, double& maxXCoord ); 00149 00157 void drawLayerChildItems( QPainter* p, QStandardItem* layerItem, double& currentYCoord, double& maxXCoord, int layerOpacity = 255 ); 00158 00161 void drawSymbol( QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition, double& symbolHeight, int layerOpacity = 255 ) const; 00162 void drawSymbolV2( QPainter* p, QgsSymbolV2* s, double currentYCoord, double& currentXPosition, double& symbolHeight, int layerOpacity = 255 ) const; 00163 void drawPointSymbol( QPainter*, QgsSymbol* s, double currentYCoord, double& currentXPosition, double& symbolHeight, int opacity = 255 ) const; 00164 void drawLineSymbol( QPainter*, QgsSymbol* s, double currentYCoord, double& currentXPosition, int opacity = 255 ) const; 00165 void drawPolygonSymbol( QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition, int opacity = 255 ) const; 00166 00168 QStringList layerIdList() const; 00169 }; 00170 00171 #endif