|
QGIS API Documentation
master-3f58142
|
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 "qgscomposerlegendstyle.h" 00022 #include "qgscomposeritem.h" 00023 #include "qgscomposerlegenditem.h" 00024 #include "qgslegendmodel.h" 00025 00026 class QgsSymbolV2; 00027 class QgsComposerGroupItem; 00028 class QgsComposerLayerItem; 00029 class QgsComposerMap; 00030 00034 class CORE_EXPORT QgsComposerLegend : public QgsComposerItem 00035 { 00036 Q_OBJECT; 00037 00038 public: 00039 QgsComposerLegend( QgsComposition* composition ); 00040 ~QgsComposerLegend(); 00041 00043 virtual int type() const { return ComposerLegend; } 00044 00046 void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget ); 00047 00049 QSizeF paintAndDetermineSize( QPainter* painter ); 00050 00051 00053 void adjustBoxSize(); 00054 00056 QgsLegendModel* model() {return &mLegendModel;} 00057 00058 //setters and getters 00059 void setTitle( const QString& t ) {mTitle = t;} 00060 QString title() const {return mTitle;} 00061 00063 QgsComposerLegendStyle & rstyle( QgsComposerLegendStyle::Style s ) { return mStyleMap[s]; } 00065 QgsComposerLegendStyle style( QgsComposerLegendStyle::Style s ) const { return mStyleMap.value( s ); } 00066 void setStyle( QgsComposerLegendStyle::Style s, const QgsComposerLegendStyle style ) { mStyleMap[s] = style; } 00067 00068 QFont styleFont( QgsComposerLegendStyle::Style s ) const { return style( s ).font(); } 00070 void setStyleFont( QgsComposerLegendStyle::Style s, const QFont& f ); 00071 00073 void setStyleMargin( QgsComposerLegendStyle::Style s, double margin ); 00074 void setStyleMargin( QgsComposerLegendStyle::Style s, QgsComposerLegendStyle::Side side, double margin ); 00075 00076 double boxSpace() const {return mBoxSpace;} 00077 void setBoxSpace( double s ) {mBoxSpace = s;} 00078 00079 double columnSpace() const {return mColumnSpace;} 00080 void setColumnSpace( double s ) { mColumnSpace = s;} 00081 00082 QColor fontColor() const {return mFontColor;} 00083 void setFontColor( const QColor& c ) {mFontColor = c;} 00084 00085 double symbolWidth() const {return mSymbolWidth;} 00086 void setSymbolWidth( double w ) {mSymbolWidth = w;} 00087 00088 double symbolHeight() const {return mSymbolHeight;} 00089 void setSymbolHeight( double h ) {mSymbolHeight = h;} 00090 00091 void setWrapChar( const QString& t ) {mWrapChar = t;} 00092 QString wrapChar() const {return mWrapChar;} 00093 00094 int columnCount() const { return mColumnCount; } 00095 void setColumnCount( int c ) { mColumnCount = c;} 00096 00097 int splitLayer() const { return mSplitLayer; } 00098 void setSplitLayer( bool s ) { mSplitLayer = s;} 00099 00100 int equalColumnWidth() const { return mEqualColumnWidth; } 00101 void setEqualColumnWidth( bool s ) { mEqualColumnWidth = s;} 00102 00103 void setComposerMap( const QgsComposerMap* map ); 00104 const QgsComposerMap* composerMap() const { return mComposerMap;} 00105 00107 void updateLegend(); 00108 00113 bool writeXML( QDomElement& elem, QDomDocument & doc ) const; 00114 00119 bool readXML( const QDomElement& itemElem, const QDomDocument& doc ); 00120 00121 public slots: 00123 void synchronizeWithModel(); 00125 void invalidateCurrentMap(); 00126 00127 protected: 00128 QString mTitle; 00129 QString mWrapChar; 00130 00131 QColor mFontColor; 00132 00134 qreal mBoxSpace; 00136 double mColumnSpace; 00137 00139 double mSymbolWidth; 00141 double mSymbolHeight; 00142 00144 double mlineSpacing; 00145 00147 int mColumnCount; 00148 00149 QgsLegendModel mLegendModel; 00150 00152 const QgsComposerMap* mComposerMap; 00153 00155 bool mSplitLayer; 00156 00158 bool mEqualColumnWidth; 00159 00160 private: 00166 class Nucleon 00167 { 00168 public: 00169 QgsComposerLegendItem* item; 00170 // Symbol size size without any space around for symbol item 00171 QSizeF symbolSize; 00172 // Label size without any space around for symbol item 00173 QSizeF labelSize; 00174 QSizeF size; 00175 // Offset of symbol label, this offset is the same for all symbol labels 00176 // of the same layer in the same column 00177 double labelXOffset; 00178 }; 00179 00189 class Atom 00190 { 00191 public: 00192 Atom(): size( QSizeF( 0, 0 ) ), column( 0 ) {} 00193 QList<Nucleon> nucleons; 00194 // Atom size including nucleons interspaces but without any space around atom. 00195 QSizeF size; 00196 int column; 00197 }; 00198 00200 QList<Atom> createAtomList( QStandardItem* rootItem, bool splitLayer ); 00201 00203 void setColumns( QList<Atom>& atomList ); 00204 00205 QgsComposerLegend(); //forbidden 00206 00207 QSizeF drawTitle( QPainter* painter = 0, QPointF point = QPointF(), Qt::AlignmentFlag halignment = Qt::AlignLeft ); 00208 00212 QSizeF drawGroupItemTitle( QgsComposerGroupItem* groupItem, QPainter* painter = 0, QPointF point = QPointF() ); 00214 QSizeF drawLayerItemTitle( QgsComposerLayerItem* layerItem, QPainter* painter = 0, QPointF point = QPointF() ); 00215 00216 Nucleon drawSymbolItem( QgsComposerLegendItem* symbolItem, QPainter* painter = 0, QPointF point = QPointF(), double labelXOffset = 0. ); 00217 00220 void drawSymbolV2( QPainter* p, QgsSymbolV2* s, double currentYCoord, double& currentXPosition, double& symbolHeight ) const; 00221 00223 QSizeF drawAtom( Atom atom, QPainter* painter = 0, QPointF point = QPointF() ); 00224 00225 double spaceAboveAtom( Atom atom ); 00226 00228 QStringList layerIdList() const; 00229 00232 QStringList splitStringForWrapping( QString stringToSplt ); 00233 00234 QMap<QgsComposerLegendStyle::Style, QgsComposerLegendStyle> mStyleMap; 00235 }; 00236 00237 #endif